PackagistApi Client
Let's consume the Packagist API., (*1)
, (*2)
Installation
This library can be found on Packagist.
The recommended way to install this is through composer., (*3)
Run these commands to install composer, the library and its dependencies:, (*4)
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar require rayrutjes/packagist-api-client
You then need to install one of the following:, (*5)
$ php composer.phar require guzzlehttp/guzzle:~5.0
$ php composer.phar require guzzlehttp/guzzle:~6.0
Usage
Initialize client
<?php
require 'vendor/autoload.php';
use PackagistApi\Client;
use PackagistApi\Adapter\GuzzleHttpAdapter;
// Create an adapter.
$adapter = new GuzzleHttpAdapter();
// Create a Client object with the previous adapter.
$packagist = new Client($adapter);
// ...
Retrieve all package names available
Accepts the following optional parameters:
- vendor
- type, (*6)
<?php
// ... initialize Client like explained above.
$packageNames = $packagist->getAllPackageNames([
'vendor' => 'composer', // Optional.
'type' => 'composer-plugin', // Optional.
]);
var_dump($packageNames);
Get a package with all its download statistics
Will throw an PackagistApi\Exception\HttpException
if the package does not exist., (*7)
<?php
// ... initialize Client like explained above.
$package = $packagist->getPackageByName('rayrutjes/packagist-api-client');
var_dump($package);
Search for packages
Accepts the following optional parameters:
- q
- tags
- type
- per_page
- page, (*8)
<?php
// ... initialize Client like explained above.
$packages = $packagist->searchPackages([
'q' => 'monolog', // Optionally filter by name.
'tags' => 'psr-3', // Optionally filter by tag.
'type' => 'symfony-bundle', // Optionally filter by type.
'per_page' => 10, // Optionally change the number of results per page.
'page' => 3, // Optionally choose the results page.
]);
var_dump($packages);
// Iterate over all search results.
$packages = [];
$page = 1;
$limit = 500;
do {
$result = $packagist->searchPackages([
'q' => 'monolog', // Optionally filter by name.
'per_page' => 100, // Optionally change the number of results per page.
'page' => $page, // Optionally choose the results page.
]);
$packages = array_merge($packages, $result['results']);
++$page;
} while (isset($result['next']) && count($packages) <= $limit);
var_dump($packages);
Get popular packages
Accepts the following optional parameters:
- per_page
- page, (*9)
<?php
// ... initialize Client like explained above.
$popularPackages = $packagist->getPopularPackages([
'per_page' => 10, // Optionally change the number of results per page.
'page' => 3, // Optionally choose the results page.
]);
var_dump($popularPackages);
// Iterate over all popular packages.
$packages = [];
$page = 1;
$limit = 500;
do {
$result = $packagist->getPopularPackages([
'per_page' => 100, // Optionally change the number of results per page.
'page' => $page, // Optionally choose the results page.
]);
$packages = array_merge($packages, $result['packages']);
++$page;
} while (isset($result['next']) && count($packages) <= $limit);
var_dump($packages);
Contributing
Please see CONTRIBUTING for details., (*10)
Changelog
Please see CHANGELOG for details., (*11)
Support
Please open an issue in github, (*12)
Contributor Code of Conduct
As contributors and maintainers of this project, we pledge to respect all people
who contribute through reporting issues, posting feature requests, updating
documentation, submitting pull requests or patches, and other activities., (*13)
We are committed to making participation in this project a harassment-free
experience for everyone, regardless of level of experience, gender, gender
identity and expression, sexual orientation, disability, personal appearance,
body size, race, age, or religion., (*14)
Examples of unacceptable behavior by participants include the use of sexual
language or imagery, derogatory comments or personal attacks, trolling, public
or private harassment, insults, or other unprofessional conduct., (*15)
Project maintainers have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct. Project maintainers who do not follow the
Code of Conduct may be removed from the project team., (*16)
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by opening an issue or contacting one or more of the project
maintainers., (*17)
This Code of Conduct is adapted from the Contributor
Covenant, version 1.0.0, available at
http://contributor-covenant.org/version/1/0/0/., (*18)
License
PackagistApi is released under the MIT License. See the bundled
LICENSE file for details., (*19)