|
11 | 11 |
|
12 | 12 | namespace FOS\HttpCache\ProxyClient;
|
13 | 13 |
|
14 |
| -use FOS\HttpCache\Exception\InvalidArgumentException; |
15 | 14 | use FOS\HttpCache\ProxyClient\Http\HttpAdapter;
|
16 |
| -use FOS\HttpCache\ProxyClient\Http\HttpAdapterInterface; |
17 |
| -use FOS\HttpCache\ProxyClient\Http\HttpAsyncAdapter; |
18 | 15 | use Http\Client\HttpAsyncClient;
|
19 |
| -use Http\Client\HttpClient; |
20 |
| -use Http\Discovery\HttpClientDiscovery; |
| 16 | +use Http\Discovery\HttpAsyncClientDiscovery; |
| 17 | +use Http\Discovery\MessageFactoryDiscovery; |
| 18 | +use Http\Message\MessageFactory; |
21 | 19 |
|
22 | 20 | /**
|
23 |
| - * Abstract caching proxy client |
| 21 | + * Abstract HTTP based caching proxy client. |
24 | 22 | *
|
25 | 23 | * @author David de Boer <[email protected]>
|
26 | 24 | */
|
27 | 25 | abstract class AbstractProxyClient implements ProxyClientInterface
|
28 | 26 | {
|
29 | 27 | /**
|
30 |
| - * HTTP client |
| 28 | + * HTTP client adapter. |
31 | 29 | *
|
32 |
| - * @var HttpAdapterInterface |
| 30 | + * @var HttpAdapter |
33 | 31 | */
|
34 | 32 | protected $httpAdapter;
|
35 | 33 |
|
| 34 | + /** |
| 35 | + * @var MessageFactory |
| 36 | + */ |
| 37 | + protected $messageFactory; |
| 38 | + |
36 | 39 | /**
|
37 | 40 | * Constructor
|
38 | 41 | *
|
39 |
| - * @param array $servers Caching proxy server hostnames or IP |
40 |
| - * addresses, including port if not port 80. |
41 |
| - * E.g. ['127.0.0.1:6081'] |
42 |
| - * @param string $baseUri Default application hostname, optionally |
43 |
| - * including base URL, for purge and refresh |
44 |
| - * requests (optional). This is required if |
45 |
| - * you purge and refresh paths instead of |
46 |
| - * absolute URLs. |
47 |
| - * @param HttpClient|HttpAsyncClient|null $httpClient If no HTTP client is supplied, a default |
48 |
| - * one will be created. |
| 42 | + * @param array $servers Caching proxy server hostnames or IP |
| 43 | + * addresses, including port if not port 80. |
| 44 | + * E.g. ['127.0.0.1:6081'] |
| 45 | + * @param string $baseUri Default application hostname, optionally |
| 46 | + * including base URL, for purge and refresh |
| 47 | + * requests (optional). This is required if |
| 48 | + * you purge and refresh paths instead of |
| 49 | + * absolute URLs. |
| 50 | + * @param HttpAsyncClient|null $httpClient Client capable of sending HTTP requests. If no |
| 51 | + * client is supplied, a default one is created. |
| 52 | + * @param MessageFactory|null $messageFactory Factory for PSR-7 messages. If none supplied, |
| 53 | + * a default one is created. |
49 | 54 | */
|
50 | 55 | public function __construct(
|
51 | 56 | array $servers,
|
52 | 57 | $baseUri = null,
|
53 |
| - $httpClient = null |
| 58 | + HttpAsyncClient $httpClient = null, |
| 59 | + MessageFactory $messageFactory = null |
54 | 60 | ) {
|
55 |
| - if ($httpClient instanceof HttpClient) { |
56 |
| - $this->httpAdapter = new HttpAdapter($servers, $baseUri, $httpClient); |
57 |
| - } elseif ($httpClient instanceof HttpAsyncClient) { |
58 |
| - $this->httpAdapter = new HttpAsyncAdapter($servers, $baseUri, $httpClient); |
59 |
| - } elseif (null === $httpClient) { |
60 |
| - $this->httpAdapter = new HttpAdapter($servers, $baseUri, HttpClientDiscovery::find()); |
61 |
| - } else { |
62 |
| - throw new InvalidArgumentException('client must either be null or implement HttpClient or HttpAsyncClient'); |
| 61 | + if (!$httpClient) { |
| 62 | + $httpClient = HttpAsyncClientDiscovery::find(); |
63 | 63 | }
|
| 64 | + $this->httpAdapter = new HttpAdapter($servers, $baseUri, $httpClient); |
| 65 | + $this->messageFactory = $messageFactory ?: MessageFactoryDiscovery::find(); |
64 | 66 | }
|
65 | 67 |
|
66 | 68 | /**
|
|
0 commit comments