Exception
3 years ago
Strategy
6 months ago
ClassDiscovery.php
3 years ago
Exception.php
3 years ago
HttpAsyncClientDiscovery.php
2 years ago
HttpClientDiscovery.php
2 years ago
MessageFactoryDiscovery.php
2 years ago
NotFoundException.php
11 months ago
Psr17FactoryDiscovery.php
6 months ago
Psr18ClientDiscovery.php
11 months ago
StreamFactoryDiscovery.php
2 years ago
UriFactoryDiscovery.php
2 years ago
HttpClientDiscovery.php
37 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaHttp\Discovery; |
| 4 | |
| 5 | use AmeliaHttp\Client\HttpClient; |
| 6 | use AmeliaHttp\Discovery\Exception\DiscoveryFailedException; |
| 7 | |
| 8 | /** |
| 9 | * Finds an HTTP Client. |
| 10 | * |
| 11 | * @author Márk Sági-Kazár <mark.sagikazar@gmail.com> |
| 12 | */ |
| 13 | final class HttpClientDiscovery extends ClassDiscovery |
| 14 | { |
| 15 | /** |
| 16 | * Finds an HTTP Client. |
| 17 | * |
| 18 | * @return HttpClient |
| 19 | * |
| 20 | * @throws Exception\NotFoundException |
| 21 | */ |
| 22 | public static function find() |
| 23 | { |
| 24 | try { |
| 25 | $client = static::findOneByType(HttpClient::class); |
| 26 | } catch (DiscoveryFailedException $e) { |
| 27 | throw new NotFoundException( |
| 28 | 'No HTTPlug clients found. Make sure to install a package providing "php-http/client-implementation". Example: "php-http/guzzle6-adapter".', |
| 29 | 0, |
| 30 | $e |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | return static::instantiateClass($client); |
| 35 | } |
| 36 | } |
| 37 |