1 | <?php |
||
37 | class HttpDispatcher |
||
38 | { |
||
39 | /** |
||
40 | * @var HttpAsyncClient |
||
41 | */ |
||
42 | private $httpClient; |
||
43 | |||
44 | /** |
||
45 | * @var UriFactory |
||
46 | */ |
||
47 | private $uriFactory; |
||
48 | |||
49 | /** |
||
50 | * Queued requests. |
||
51 | * |
||
52 | * @var RequestInterface[] |
||
53 | */ |
||
54 | private $queue = []; |
||
55 | |||
56 | /** |
||
57 | * Caching proxy server host names or IP addresses. |
||
58 | * |
||
59 | * @var UriInterface[] |
||
60 | */ |
||
61 | private $servers; |
||
62 | |||
63 | /** |
||
64 | * Application host name and optional base URL. |
||
65 | * |
||
66 | * @var UriInterface |
||
67 | */ |
||
68 | private $baseUri; |
||
69 | |||
70 | /** |
||
71 | * If you specify a custom HTTP client, make sure that it converts HTTP |
||
72 | * errors to exceptions. |
||
73 | * |
||
74 | * @param string[] $servers Caching proxy server hostnames or IP |
||
75 | * addresses, including port if not port 80. |
||
76 | * E.g. ['127.0.0.1:6081'] |
||
77 | * @param string $baseUri Default application hostname, optionally |
||
78 | * including base URL, for purge and refresh |
||
79 | * requests (optional). This is required if |
||
80 | * you purge and refresh paths instead of |
||
81 | * absolute URLs |
||
82 | * @param HttpAsyncClient|null $httpClient Client capable of sending HTTP requests. If no |
||
83 | * client is supplied, a default one is created |
||
84 | * @param UriFactory|null $uriFactory Factory for PSR-7 URIs. If not specified, a |
||
85 | * default one is created |
||
86 | */ |
||
87 | 39 | public function __construct( |
|
105 | |||
106 | /** |
||
107 | * Queue invalidation request. |
||
108 | * |
||
109 | * @param RequestInterface $invalidationRequest |
||
110 | */ |
||
111 | 33 | public function invalidate(RequestInterface $invalidationRequest) |
|
125 | |||
126 | /** |
||
127 | * Send all pending invalidation requests and make sure the requests have terminated and gather exceptions. |
||
128 | * |
||
129 | * @return int The number of cache invalidations performed per caching server |
||
130 | * |
||
131 | * @throws ExceptionCollection If any errors occurred during flush |
||
132 | */ |
||
133 | 33 | public function flush() |
|
172 | |||
173 | /** |
||
174 | * Duplicate a request for each caching server. |
||
175 | * |
||
176 | * @param RequestInterface $request The request to duplicate for each configured server |
||
177 | * |
||
178 | * @return RequestInterface[] |
||
179 | */ |
||
180 | 32 | private function fanOut(RequestInterface $request) |
|
229 | |||
230 | /** |
||
231 | * Set caching proxy server URI objects, validating them. |
||
232 | * |
||
233 | * @param string[] $servers Caching proxy proxy server hostnames or IP |
||
234 | * addresses, including port if not port 80. |
||
235 | * E.g. ['127.0.0.1:6081'] |
||
236 | * |
||
237 | * @throws InvalidUrlException If server is invalid or contains URL |
||
238 | * parts other than scheme, host, port |
||
239 | */ |
||
240 | 39 | private function setServers(array $servers) |
|
247 | |||
248 | /** |
||
249 | * Set application base URI that will be prefixed to relative purge and |
||
250 | * refresh requests, and validate it. |
||
251 | * |
||
252 | * @param string $uriString Your application’s base URI |
||
253 | * |
||
254 | * @throws InvalidUrlException If the base URI is not a valid URI |
||
255 | */ |
||
256 | 36 | private function setBaseUri($uriString = null) |
|
266 | |||
267 | /** |
||
268 | * Filter a URL. |
||
269 | * |
||
270 | * Prefix the URL with "http://" if it has no scheme, then check the URL |
||
271 | * for validity. You can specify what parts of the URL are allowed. |
||
272 | * |
||
273 | * @param string $uriString |
||
274 | * @param string[] $allowedParts Array of allowed URL parts (optional) |
||
275 | * |
||
276 | * @return UriInterface Filtered URI (with default scheme if there was no scheme) |
||
277 | * |
||
278 | * @throws InvalidUrlException If URL is invalid, the scheme is not http or |
||
279 | * contains parts that are not expected |
||
280 | */ |
||
281 | 39 | private function filterUri($uriString, array $allowedParts = []) |
|
317 | |||
318 | /** |
||
319 | * Build a request signature based on the request data. Unique for every different request, identical |
||
320 | * for the same requests. |
||
321 | * |
||
322 | * This signature is used to avoid sending the same invalidation request twice. |
||
323 | * |
||
324 | * @param RequestInterface $request An invalidation request |
||
325 | * |
||
326 | * @return string A signature for this request |
||
327 | */ |
||
328 | 32 | private function getRequestSignature(RequestInterface $request) |
|
335 | } |
||
336 |
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: