8000 GitHub - clue/reactphp-packagist-api at v1.2.0
[go: up one dir, main page]

Skip to content

Simple async access to packagist.org's API, like listing project details, number of downloads etc., built on top of ReactPHP.

License

Notifications You must be signed in to change notification settings

clue/reactphp-packagist-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clue/packagist-api-react Build Status

Simple async access to packagist.org's API, like listing project details, number of downloads, etc.

This is an async version of KnpLab's excellent packagist-api, but built upon React PHP's non-blocking event-loop. It uses the async HTTP client library buzz-react to process any number of requests in parallel.

In a nutshell, it allows you to issue multiple requests to the packagist API in parallel and process them out of order whenever their results arrive - while trying to hide all the nifty details of async processing. On top of that it provides a very easy to use API, very much similar to the original packagist-api, enriched with the comfort of React PHP's Promises/A.

Table of Contents

Quickstart example

Once installed, you can use the following code to fetch package information from packagist.org:

$loop = React\EventLoop\Factory::create();
$browser = new Clue\React\Buzz\Browser($loop);
$client = new Client($browser);

$client->get('clue/phar-composer')->then(function (Package $package) {
    var_dump($package->getName(), $package->getDescription());
});

$loop->run();

See also the examples.

Usage

Client

The Client is responsible for assembling and sending HTTP requests to the remote Packagist API. It requires a Browser object bound to the main EventLoop in order to handle async requests:

$loop = React\EventLoop\Factory::create();
$browser = new Clue\React\Buzz\Browser($loop);

$client = new Client($browser);

If you need custom DNS, SSL/TLS or proxy settings, you can explicitly pass a custom Browser instance.

Promises

All public methods on the Client resemble the API provided by KnpLab's packagist-api, except for an async shift in their return values: Sending requests is async (non-blocking), so you can actually send multiple requests in parallel. Packagist will respond to each request with a response message, the order is not guaranteed. Sending requests uses a Promise-based interface that makes it easy to react to when a request is fulfilled (i.e. either successfully resolved or rejected with an error).

search()

The search($query, $filters = array()) method can be used to search packages matching the given query string and optionally matching the given filter parameter. It resolves with an array containing zero or more Package objects.

$client->search('packagist')->then(function ($results) {
    foreach ($results as $result) {
        echo $package->getName() . PHP_EOL;
    }
});

get()

The get($name) method can be used to get package details for the given package name. It resolves with a single Package object.

$client->get('clue/packagist-api-react')->then(function (Package $package) {
    echo $package->getDescription();
});

all()

The all($filters = array()) method an be used to list all package names, optionally matching the given filter parameter. It resolves with an array of package names.

$client->all(array('vendor' => 'clue'))->then(function ($list) {
    // array containing (among others) "clue/packagist-api-react"
});

Package

The Package class represents information about a given composer package. This class is part of the underlying KnpLab/packagist-api, its full name is actually Packagist\Api\Result\Package.

See its class outline for all available methods.

getName()

The getName() method can be used to get the package name.

getDescription()

The getDescription() method can be used to the package description.

Install

The recommended way to install this library is through Composer. New to Composer?

This project follows SemVer. This will install the latest supported version:

$ composer require clue/packagist-api-react:^1.2

See also the CHANGELOG for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.3 through current PHP 7+ and HHVM. It's highly recommended to use PHP 7+ for this project.

Tests

To run the test suite, you first need to clone this repo and then install all dependencies through Composer:

$ composer install

To run the test suite, go to the project root and run:

$ php vendor/bin/phpunit

License

MIT

About

Simple async access to packagist.org's API, like listing project details, number of downloads etc., built on top of ReactPHP.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages

0