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 | 38 | * @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 | public function __construct( |
||
105 | |||
106 | 31 | /** |
|
107 | * Queue invalidation request. |
||
108 | 31 | * |
|
109 | 1 | * @param RequestInterface $invalidationRequest |
|
110 | */ |
||
111 | public function invalidate(RequestInterface $invalidationRequest) |
||
125 | 32 | ||
126 | /** |
||
127 | 32 | * Send all pending invalidation requests and make sure the requests have terminated and gather exceptions. |
|
128 | * |
||
129 | 32 | * @return int The number of cache invalidations performed per caching server |
|
130 | * |
||
131 | 32 | * @throws ExceptionCollection If any errors occurred during flush |
|
132 | 31 | */ |
|
133 | public function flush() |
||
172 | |||
173 | 31 | /** |
|
174 | * Duplicate a request for each caching server. |
||
175 | * |
||
176 | * @param RequestInterface $request The request to duplicate for each configured server |
||
177 | 31 | * |
|
178 | 31 | * @return RequestInterface[] |
|
179 | */ |
||
180 | 5 | private function fanOut(RequestInterface $request) |
|
229 | 38 | ||
230 | /** |
||
231 | 38 | * Set caching proxy server URI objects, validating them. |
|
232 | 38 | * |
|
233 | 38 | * @param string[] $servers Caching proxy proxy server hostnames or IP |
|
234 | 35 | * addresses, including port if not port 80. |
|
235 | 35 | * 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 | private function setServers(array $servers) |
||
247 | 35 | ||
248 | 1 | /** |
|
249 | * Set application base URI that will be prefixed to relative purge and |
||
250 | 1 | * refresh requests, and validate it. |
|
251 | * |
||
252 | * @param string $uriString Your application’s base URI |
||
253 | 34 | * |
|
254 | 33 | * @throws InvalidUrlException If the base URI is not a valid URI |
|
255 | */ |
||
256 | private function setBaseUri($uriString = null) |
||
266 | |||
267 | /** |
||
268 | * Filter a URL. |
||
269 | * |
||
270 | 38 | * 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 | 38 | * |
|
273 | 1 | * @param string $uriString |
|
274 | 1 | * @param string[] $allowedParts Array of allowed URL parts (optional) |
|
275 | 1 | * |
|
276 | 1 | * @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 | private function filterUri($uriString, array $allowedParts = []) |
||
317 | 31 | ||
318 | /** |
||
319 | 31 | * Build a request signature based on the request data. Unique for every different request, identical |
|
320 | 31 | * for the same requests. |
|
321 | * |
||
322 | 31 | * 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 | 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: