PHP code example of rayrutjes / packagist-api-client
1. Go to this page and download the library: Download rayrutjes/packagist-api-client library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rayrutjes / packagist-api-client example snippets
ackagistApi\Client;
use PackagistApi\Adapter\GuzzleHttpAdapter;
// Create an adapter.
$adapter = new GuzzleHttpAdapter();
// Create a Client object with the previous adapter.
$packagist = new Client($adapter);
// ...
// ... initialize Client like explained above.
$packageNames = $packagist->getAllPackageNames([
'vendor' => 'composer', // Optional.
'type' => 'composer-plugin', // Optional.
]);
var_dump($packageNames);
// ... initialize Client like explained above.
$package = $packagist->getPackageByName('rayrutjes/packagist-api-client');
var_dump($package);
// ... 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);
// ... 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);
bash
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar
bash
$ php composer.phar uire guzzlehttp/guzzle:~6.0