Debian Codegraph @

lib/3rdParty/composer/php-http/discovery/src/Psr18Client.php

raw symbols SCIP
1 <?php
2
3 namespace Http\Discovery;
4
5 use Psr\Http\Client\ClientInterface;
6 use Psr\Http\Message\RequestFactoryInterface;
7 use Psr\Http\Message\RequestInterface;
8 use Psr\Http\Message\ResponseFactoryInterface;
9 use Psr\Http\Message\ResponseInterface;
10 use Psr\Http\Message\ServerRequestFactoryInterface;
11 use Psr\Http\Message\StreamFactoryInterface;
12 use Psr\Http\Message\UploadedFileFactoryInterface;
13 use Psr\Http\Message\UriFactoryInterface;
14
15 /**
16 * A generic PSR-18 and PSR-17 implementation.
17 *
18 * You can create this class with concrete client and factory instances
19 * or let it use discovery to find suitable implementations as needed.
20 *
21 * @author Nicolas Grekas <[email protected]>
22 */
23 class Psr18Client extends Psr17Factory implements ClientInterface
24 {
25 private $client;
26
27 public function __construct(
28 ?ClientInterface $client = null,
29 ?RequestFactoryInterface $requestFactory = null,
30 ?ResponseFactoryInterface $responseFactory = null,
31 ?ServerRequestFactoryInterface $serverRequestFactory = null,
32 ?StreamFactoryInterface $streamFactory = null,
33 ?UploadedFileFactoryInterface $uploadedFileFactory = null,
34 ?UriFactoryInterface $uriFactory = null
35 ) {
36 $requestFactory ?? $requestFactory = $client instanceof RequestFactoryInterface ? $client : null;
37 $responseFactory ?? $responseFactory = $client instanceof ResponseFactoryInterface ? $client : null;
38 $serverRequestFactory ?? $serverRequestFactory = $client instanceof ServerRequestFactoryInterface ? $client : null;
39 $streamFactory ?? $streamFactory = $client instanceof StreamFactoryInterface ? $client : null;
40 $uploadedFileFactory ?? $uploadedFileFactory = $client instanceof UploadedFileFactoryInterface ? $client : null;
41 $uriFactory ?? $uriFactory = $client instanceof UriFactoryInterface ? $client : null;
42
43 parent::__construct($requestFactory, $responseFactory, $serverRequestFactory, $streamFactory, $uploadedFileFactory, $uriFactory);
44
45 $this->client = $client ?? Psr18ClientDiscovery::find();
46 }
47
48 public function sendRequest(RequestInterface $request): ResponseInterface
49 {
50 return $this->client->sendRequest($request);
51 }
52 }