1 | <?php |
||
35 | class HttpDispatcher |
||
36 | { |
||
37 | /** |
||
38 | * @var HttpAsyncClient |
||
39 | */ |
||
40 | private $httpClient; |
||
41 | |||
42 | /** |
||
43 | * @var UriFactory |
||
44 | */ |
||
45 | private $uriFactory; |
||
46 | |||
47 | /** |
||
48 | * Queued requests. |
||
49 | * |
||
50 | * @var RequestInterface[] |
||
51 | */ |
||
52 | private $queue = []; |
||
53 | |||
54 | /** |
||
55 | * Caching proxy server host names or IP addresses. |
||
56 | * |
||
57 | * @var UriInterface[] |
||
58 | */ |
||
59 | private $servers; |
||
60 | |||
61 | /** |
||
62 | * Application host name and optional base URL. |
||
63 | * |
||
64 | * @var UriInterface |
||
65 | */ |
||
66 | private $baseUri; |
||
67 | |||
68 | /** |
||
69 | * @param string[] $servers Caching proxy server hostnames or IP |
||
70 | * addresses, including port if not port 80. |
||
71 | * E.g. ['127.0.0.1:6081'] |
||
72 | * @param string $baseUri Default application hostname, optionally |
||
73 | * including base URL, for purge and refresh |
||
74 | * requests (optional). This is required if |
||
75 | * you purge and refresh paths instead of |
||
76 | * absolute URLs |
||
77 | * @param HttpAsyncClient|null $httpClient Client capable of sending HTTP requests. If no |
||
78 | * client is supplied, a default one is created |
||
79 | * @param UriFactory|null $uriFactory Factory for PSR-7 URIs. If not specified, a |
||
80 | * default one is created |
||
81 | */ |
||
82 | 38 | public function __construct( |
|
94 | |||
95 | /** |
||
96 | * Queue invalidation request. |
||
97 | * |
||
98 | * @param RequestInterface $invalidationRequest |
||
99 | */ |
||
100 | 32 | public function invalidate(RequestInterface $invalidationRequest) |
|
114 | |||
115 | /** |
||
116 | * Send all pending invalidation requests and make sure the requests have terminated and gather exceptions. |
||
117 | * |
||
118 | * @return int The number of cache invalidations performed per caching server |
||
119 | * |
||
120 | * @throws ExceptionCollection If any errors occurred during flush |
||
121 | */ |
||
122 | 32 | public function flush() |
|
161 | |||
162 | /** |
||
163 | * Duplicate a request for each caching server. |
||
164 | * |
||
165 | * @param RequestInterface $request The request to duplicate for each configured server |
||
166 | * |
||
167 | * @return RequestInterface[] |
||
168 | */ |
||
169 | 31 | private function fanOut(RequestInterface $request) |
|
218 | |||
219 | /** |
||
220 | * Set caching proxy server URI objects, validating them. |
||
221 | * |
||
222 | * @param string[] $servers Caching proxy proxy server hostnames or IP |
||
223 | * addresses, including port if not port 80. |
||
224 | * E.g. ['127.0.0.1:6081'] |
||
225 | * |
||
226 | * @throws InvalidUrlException If server is invalid or contains URL |
||
227 | * parts other than scheme, host, port |
||
228 | */ |
||
229 | 38 | private function setServers(array $servers) |
|
236 | |||
237 | /** |
||
238 | * Set application base URI that will be prefixed to relative purge and |
||
239 | * refresh requests, and validate it. |
||
240 | * |
||
241 | * @param string $uriString Your application’s base URI |
||
242 | * |
||
243 | * @throws InvalidUrlException If the base URI is not a valid URI |
||
244 | */ |
||
245 | 35 | private function setBaseUri($uriString = null) |
|
255 | |||
256 | /** |
||
257 | * Filter a URL. |
||
258 | * |
||
259 | * Prefix the URL with "http://" if it has no scheme, then check the URL |
||
260 | * for validity. You can specify what parts of the URL are allowed. |
||
261 | * |
||
262 | * @param string $uriString |
||
263 | * @param string[] $allowedParts Array of allowed URL parts (optional) |
||
264 | * |
||
265 | * @return UriInterface Filtered URI (with default scheme if there was no scheme) |
||
266 | * |
||
267 | * @throws InvalidUrlException If URL is invalid, the scheme is not http or |
||
268 | * contains parts that are not expected |
||
269 | */ |
||
270 | 38 | private function filterUri($uriString, array $allowedParts = []) |
|
306 | |||
307 | /** |
||
308 | * Build a request signature based on the request data. Unique for every different request, identical |
||
309 | * for the same requests. |
||
310 | * |
||
311 | * This signature is used to avoid sending the same invalidation request twice. |
||
312 | * |
||
313 | * @param RequestInterface $request An invalidation request |
||
314 | * |
||
315 | * @return string A signature for this request |
||
316 | */ |
||
317 | 31 | private function getRequestSignature(RequestInterface $request) |
|
324 | } |
||
325 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: