| 1 | <?php |
||
| 16 | * Transport Factory. |
||
| 17 | */ |
||
| 18 | class Factory |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Creates the transport based on which classes are defined. |
||
| 22 | * |
||
| 23 | * @throws RuntimeException |
||
| 24 | */ |
||
| 25 | 4 | public static function createTransport(?RuntimeInterface $runtime = null): TransportInterface |
|
| 26 | { |
||
| 27 | 4 | $runtime ??= new Runtime(); |
|
|
|
|||
| 28 | |||
| 29 | 3 | if ($runtime->classExists(Psr18ClientDiscovery::class) && $runtime->classExists(Psr17FactoryDiscovery::class)) { |
|
| 30 | 2 | try { |
|
| 31 | return new Psr7ClientTransport( |
||
| 32 | Psr18ClientDiscovery::find(), |
||
| 33 | Psr17FactoryDiscovery::findRequestFactory(), |
||
| 34 | Psr17FactoryDiscovery::findStreamFactory() |
||
| 35 | 3 | ); |
|
| 36 | 1 | } catch (NotFoundException $e) { |
|
| 37 | // @ignoreException |
||
| 38 | } |
||
| 39 | 2 | } |
|
| 40 | 1 | ||
| 41 | if ($runtime->classExists(Client::class)) { |
||
| 42 | return new Guzzle6Transport(); |
||
| 43 | 1 | } |
|
| 44 | |||
| 45 | if ($runtime->extensionLoaded('curl')) { |
||
| 46 | return new CurlExtensionTransport(); |
||
| 52 |