1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the API Platform project. |
||
5 | * |
||
6 | * (c) Kévin Dunglas <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | declare(strict_types=1); |
||
13 | |||
14 | namespace ApiPlatform\Core\Serializer; |
||
15 | |||
16 | trait CacheKeyTrait |
||
17 | { |
||
18 | /** |
||
19 | * @return string|bool |
||
20 | */ |
||
21 | private function getCacheKey(?string $format, array $context) |
||
22 | { |
||
23 | foreach ($context[self::EXCLUDE_FROM_CACHE_KEY] ?? $this->defaultContext[self::EXCLUDE_FROM_CACHE_KEY] as $key) { |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
24 | unset($context[$key]); |
||
25 | } |
||
26 | unset($context[self::EXCLUDE_FROM_CACHE_KEY]); |
||
27 | unset($context['cache_key']); // avoid artificially different keys |
||
28 | |||
29 | try { |
||
30 | return md5($format.serialize($context)); |
||
31 | } catch (\Exception $exception) { |
||
32 | // The context cannot be serialized, skip the cache |
||
33 | return false; |
||
34 | } |
||
35 | } |
||
36 | } |
||
37 |