Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/http-kernel/HttpCache/Store.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
27 protected $root; | 27 protected $root; |
28 private $keyCache; | 28 private $keyCache; |
29 private $locks; | 29 private $locks; |
30 | 30 |
31 /** | 31 /** |
32 * Constructor. | |
33 * | |
34 * @param string $root The path to the cache directory | 32 * @param string $root The path to the cache directory |
35 * | 33 * |
36 * @throws \RuntimeException | 34 * @throws \RuntimeException |
37 */ | 35 */ |
38 public function __construct($root) | 36 public function __construct($root) |
60 } | 58 } |
61 | 59 |
62 /** | 60 /** |
63 * Tries to lock the cache for a given Request, without blocking. | 61 * Tries to lock the cache for a given Request, without blocking. |
64 * | 62 * |
65 * @param Request $request A Request instance | |
66 * | |
67 * @return bool|string true if the lock is acquired, the path to the current lock otherwise | 63 * @return bool|string true if the lock is acquired, the path to the current lock otherwise |
68 */ | 64 */ |
69 public function lock(Request $request) | 65 public function lock(Request $request) |
70 { | 66 { |
71 $key = $this->getCacheKey($request); | 67 $key = $this->getCacheKey($request); |
89 } | 85 } |
90 | 86 |
91 /** | 87 /** |
92 * Releases the lock for the given Request. | 88 * Releases the lock for the given Request. |
93 * | 89 * |
94 * @param Request $request A Request instance | |
95 * | |
96 * @return bool False if the lock file does not exist or cannot be unlocked, true otherwise | 90 * @return bool False if the lock file does not exist or cannot be unlocked, true otherwise |
97 */ | 91 */ |
98 public function unlock(Request $request) | 92 public function unlock(Request $request) |
99 { | 93 { |
100 $key = $this->getCacheKey($request); | 94 $key = $this->getCacheKey($request); |
130 return (bool) $wouldBlock; | 124 return (bool) $wouldBlock; |
131 } | 125 } |
132 | 126 |
133 /** | 127 /** |
134 * Locates a cached Response for the Request provided. | 128 * Locates a cached Response for the Request provided. |
135 * | |
136 * @param Request $request A Request instance | |
137 * | 129 * |
138 * @return Response|null A Response instance, or null if no cache entry was found | 130 * @return Response|null A Response instance, or null if no cache entry was found |
139 */ | 131 */ |
140 public function lookup(Request $request) | 132 public function lookup(Request $request) |
141 { | 133 { |
157 | 149 |
158 if (null === $match) { | 150 if (null === $match) { |
159 return; | 151 return; |
160 } | 152 } |
161 | 153 |
162 list($req, $headers) = $match; | 154 $headers = $match[1]; |
163 if (file_exists($body = $this->getPath($headers['x-content-digest'][0]))) { | 155 if (file_exists($body = $this->getPath($headers['x-content-digest'][0]))) { |
164 return $this->restoreResponse($headers, $body); | 156 return $this->restoreResponse($headers, $body); |
165 } | 157 } |
166 | 158 |
167 // TODO the metaStore referenced an entity that doesn't exist in | 159 // TODO the metaStore referenced an entity that doesn't exist in |
172 /** | 164 /** |
173 * Writes a cache entry to the store for the given Request and Response. | 165 * Writes a cache entry to the store for the given Request and Response. |
174 * | 166 * |
175 * Existing entries are read and any that match the response are removed. This | 167 * Existing entries are read and any that match the response are removed. This |
176 * method calls write with the new list of cache entries. | 168 * method calls write with the new list of cache entries. |
177 * | |
178 * @param Request $request A Request instance | |
179 * @param Response $response A Response instance | |
180 * | 169 * |
181 * @return string The key under which the response is stored | 170 * @return string The key under which the response is stored |
182 * | 171 * |
183 * @throws \RuntimeException | 172 * @throws \RuntimeException |
184 */ | 173 */ |
208 foreach ($this->getMetadata($key) as $entry) { | 197 foreach ($this->getMetadata($key) as $entry) { |
209 if (!isset($entry[1]['vary'][0])) { | 198 if (!isset($entry[1]['vary'][0])) { |
210 $entry[1]['vary'] = array(''); | 199 $entry[1]['vary'] = array(''); |
211 } | 200 } |
212 | 201 |
213 if ($vary != $entry[1]['vary'][0] || !$this->requestsMatch($vary, $entry[0], $storedEnv)) { | 202 if ($entry[1]['vary'][0] != $vary || !$this->requestsMatch($vary, $entry[0], $storedEnv)) { |
214 $entries[] = $entry; | 203 $entries[] = $entry; |
215 } | 204 } |
216 } | 205 } |
217 | 206 |
218 $headers = $this->persistResponse($response); | 207 $headers = $this->persistResponse($response); |
228 } | 217 } |
229 | 218 |
230 /** | 219 /** |
231 * Returns content digest for $response. | 220 * Returns content digest for $response. |
232 * | 221 * |
233 * @param Response $response | |
234 * | |
235 * @return string | 222 * @return string |
236 */ | 223 */ |
237 protected function generateContentDigest(Response $response) | 224 protected function generateContentDigest(Response $response) |
238 { | 225 { |
239 return 'en'.hash('sha256', $response->getContent()); | 226 return 'en'.hash('sha256', $response->getContent()); |
240 } | 227 } |
241 | 228 |
242 /** | 229 /** |
243 * Invalidates all cache entries that match the request. | 230 * Invalidates all cache entries that match the request. |
244 * | |
245 * @param Request $request A Request instance | |
246 * | 231 * |
247 * @throws \RuntimeException | 232 * @throws \RuntimeException |
248 */ | 233 */ |
249 public function invalidate(Request $request) | 234 public function invalidate(Request $request) |
250 { | 235 { |
400 return false; | 385 return false; |
401 } | 386 } |
402 | 387 |
403 $tmpFile = tempnam(dirname($path), basename($path)); | 388 $tmpFile = tempnam(dirname($path), basename($path)); |
404 if (false === $fp = @fopen($tmpFile, 'wb')) { | 389 if (false === $fp = @fopen($tmpFile, 'wb')) { |
390 @unlink($tmpFile); | |
391 | |
405 return false; | 392 return false; |
406 } | 393 } |
407 @fwrite($fp, $data); | 394 @fwrite($fp, $data); |
408 @fclose($fp); | 395 @fclose($fp); |
409 | 396 |
410 if ($data != file_get_contents($tmpFile)) { | 397 if ($data != file_get_contents($tmpFile)) { |
398 @unlink($tmpFile); | |
399 | |
411 return false; | 400 return false; |
412 } | 401 } |
413 | 402 |
414 if (false === @rename($tmpFile, $path)) { | 403 if (false === @rename($tmpFile, $path)) { |
404 @unlink($tmpFile); | |
405 | |
415 return false; | 406 return false; |
416 } | 407 } |
417 } | 408 } |
418 | 409 |
419 @chmod($path, 0666 & ~umask()); | 410 @chmod($path, 0666 & ~umask()); |
432 * | 423 * |
433 * If the same URI can have more than one representation, based on some | 424 * If the same URI can have more than one representation, based on some |
434 * headers, use a Vary header to indicate them, and each representation will | 425 * headers, use a Vary header to indicate them, and each representation will |
435 * be stored independently under the same cache key. | 426 * be stored independently under the same cache key. |
436 * | 427 * |
437 * @param Request $request A Request instance | |
438 * | |
439 * @return string A key for the given Request | 428 * @return string A key for the given Request |
440 */ | 429 */ |
441 protected function generateCacheKey(Request $request) | 430 protected function generateCacheKey(Request $request) |
442 { | 431 { |
443 return 'md'.hash('sha256', $request->getUri()); | 432 return 'md'.hash('sha256', $request->getUri()); |
444 } | 433 } |
445 | 434 |
446 /** | 435 /** |
447 * Returns a cache key for the given Request. | 436 * Returns a cache key for the given Request. |
448 * | |
449 * @param Request $request A Request instance | |
450 * | 437 * |
451 * @return string A key for the given Request | 438 * @return string A key for the given Request |
452 */ | 439 */ |
453 private function getCacheKey(Request $request) | 440 private function getCacheKey(Request $request) |
454 { | 441 { |
460 } | 447 } |
461 | 448 |
462 /** | 449 /** |
463 * Persists the Request HTTP headers. | 450 * Persists the Request HTTP headers. |
464 * | 451 * |
465 * @param Request $request A Request instance | |
466 * | |
467 * @return array An array of HTTP headers | 452 * @return array An array of HTTP headers |
468 */ | 453 */ |
469 private function persistRequest(Request $request) | 454 private function persistRequest(Request $request) |
470 { | 455 { |
471 return $request->headers->all(); | 456 return $request->headers->all(); |
472 } | 457 } |
473 | 458 |
474 /** | 459 /** |
475 * Persists the Response HTTP headers. | 460 * Persists the Response HTTP headers. |
476 * | |
477 * @param Response $response A Response instance | |
478 * | 461 * |
479 * @return array An array of HTTP headers | 462 * @return array An array of HTTP headers |
480 */ | 463 */ |
481 private function persistResponse(Response $response) | 464 private function persistResponse(Response $response) |
482 { | 465 { |