php-http / discovery
Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations
Installs: 212 880 192
Dependents: 1 052
Suggesters: 19
Security: 0
Stars: 1 271
Watchers: 14
Forks: 49
Open Issues: 4
Type:composer-plugin
Requires
- php: ^7.1 || ^8.0
- composer-plugin-api: ^1.0|^2.0
Requires (Dev)
- composer/composer: ^1.0.2|^2.0
- graham-campbell/phpspec-skip-example-extension: ^5.0
- php-http/httplug: ^1.0 || ^2.0
- php-http/message-factory: ^1.0
- phpspec/phpspec: ^5.1 || ^6.1 || ^7.3
- sebastian/comparator: ^3.0.5 || ^4.0.8
- symfony/phpunit-bridge: ^6.4.4 || ^7.0.1
Provides
Conflicts
- 1.x-dev
- 1.20.0
- 1.19.4
- 1.19.3
- 1.19.2
- 1.19.1
- 1.19.0
- 1.18.1
- 1.18.0
- 1.17.0
- 1.16.0
- 1.15.3
- 1.15.2
- 1.15.1
- 1.15.0
- 1.14.3
- 1.14.2
- 1.14.1
- 1.14.0
- 1.13.0
- 1.12.0
- 1.11.0
- 1.10.0
- 1.9.1
- 1.9.0
- 1.8.0
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.1
- 1.6.0
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.1
- 1.2.0
- v1.1.1
- v1.1.0
- v1.0.0
- v0.9.1
- v0.9.0
- v0.8.0
- v0.7.0
- v0.6.4
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.0
- v0.4.0
- v0.3.0
- 0.2.0
- v0.1.1
- v0.1.0
This package is auto-updated.
Last update: 2024-11-02 11:31:27 UTC
README
This library provides auto-discovery and auto-installation of well-known PSR-17, PSR-18 and HTTPlug implementations.
Install
Via Composer
composer require php-http/discovery
Usage as a library author
Please see the official documentation.
If your library/SDK needs a PSR-18 client, here is a quick example.
First, you need to install a PSR-18 client and a PSR-17 factory implementations. This should be done only for dev dependencies as you don't want to force a specific implementation on your users:
composer require --dev symfony/http-client composer require --dev nyholm/psr7
Then, you can disable the Composer plugin embeded in php-http/discovery
because you just installed the dev dependencies you need for testing:
composer config allow-plugins.php-http/discovery false
Finally, you need to require php-http/discovery
and the generic implementations
that your library is going to need:
composer require 'php-http/discovery:^1.17' composer require 'psr/http-client-implementation:*' composer require 'psr/http-factory-implementation:*'
Now, you're ready to make an HTTP request:
use Http\Discovery\Psr18Client; $client = new Psr18Client(); $request = $client->createRequest('GET', 'https://example.com'); $response = $client->sendRequest($request);
Internally, this code will use whatever PSR-7, PSR-17 and PSR-18 implementations that your users have installed.
Usage as a library user
If you use a library/SDK that requires php-http/discovery
, you can configure
the auto-discovery mechanism to use a specific implementation when many are
available in your project.
For example, if you have both nyholm/psr7
and guzzlehttp/guzzle
in your
project, you can tell php-http/discovery
to use guzzlehttp/guzzle
instead of
nyholm/psr7
by running the following command:
composer config extra.discovery.psr/http-factory-implementation GuzzleHttp\\Psr7\\HttpFactory
This will update your composer.json
file to add the following configuration:
{ "extra": { "discovery": { "psr/http-factory-implementation": "GuzzleHttp\\Psr7\\HttpFactory" } } }
Don't forget to run composer install
to apply the changes, and ensure that
the composer plugin is enabled:
composer config allow-plugins.php-http/discovery true
composer install
Testing
composer test
Contributing
Please see our contributing guide.
Security
If you discover any security related issues, please contact us at security@php-http.org.
License
The MIT License (MIT). Please see License File for more information.