|
24 | 24 | use ApiPlatform\Metadata\ResourceAccessCheckerInterface; |
25 | 25 | use ApiPlatform\Metadata\ResourceClassResolverInterface; |
26 | 26 | use ApiPlatform\Metadata\Util\ClassInfoTrait; |
27 | | -use ApiPlatform\Serializer\CacheKeyTrait; |
28 | 27 | use ApiPlatform\Serializer\ItemNormalizer as BaseItemNormalizer; |
29 | 28 | use Psr\Log\LoggerInterface; |
30 | 29 | use Psr\Log\NullLogger; |
|
40 | 39 | */ |
41 | 40 | final class ItemNormalizer extends BaseItemNormalizer |
42 | 41 | { |
43 | | - use CacheKeyTrait; |
44 | 42 | use ClassInfoTrait; |
45 | 43 |
|
46 | 44 | public const FORMAT = 'graphql'; |
47 | 45 | public const ITEM_RESOURCE_CLASS_KEY = '#itemResourceClass'; |
48 | 46 | public const ITEM_IDENTIFIERS_KEY = '#itemIdentifiers'; |
49 | 47 |
|
50 | | - private array $safeCacheKeysCache = []; |
51 | | - |
52 | 48 | public function __construct(PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, IriConverterInterface $iriConverter, private readonly IdentifiersExtractorInterface $identifiersExtractor, ResourceClassResolverInterface $resourceClassResolver, ?PropertyAccessorInterface $propertyAccessor = null, ?NameConverterInterface $nameConverter = null, ?ClassMetadataFactoryInterface $classMetadataFactory = null, ?LoggerInterface $logger = null, ?ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, ?ResourceAccessCheckerInterface $resourceAccessChecker = null) |
53 | 49 | { |
54 | 50 | parent::__construct($propertyNameCollectionFactory, $propertyMetadataFactory, $iriConverter, $resourceClassResolver, $propertyAccessor, $nameConverter, $classMetadataFactory, $logger ?: new NullLogger(), $resourceMetadataCollectionFactory, $resourceAccessChecker); |
@@ -90,12 +86,6 @@ public function normalize(mixed $data, ?string $format = null, array $context = |
90 | 86 | return parent::normalize($data, $format, $context); |
91 | 87 | } |
92 | 88 |
|
93 | | - if ($this->isCacheKeySafe($context)) { |
94 | | - $context['cache_key'] = $this->getCacheKey($format, $context); |
95 | | - } else { |
96 | | - $context['cache_key'] = false; |
97 | | - } |
98 | | - |
99 | 89 | unset($context['operation_name'], $context['operation']); // Remove operation and operation_name only when cache key has been created |
100 | 90 | $normalizedData = parent::normalize($data, $format, $context); |
101 | 91 | if (!\is_array($normalizedData)) { |
@@ -161,32 +151,4 @@ protected function setAttributeValue(object $object, string $attribute, mixed $v |
161 | 151 |
|
162 | 152 | parent::setAttributeValue($object, $attribute, $value, $format, $context); |
163 | 153 | } |
164 | | - |
165 | | - /** |
166 | | - * Check if any property contains a security grants, which makes the cache key not safe, |
167 | | - * as allowed_properties can differ for 2 instances of the same object. |
168 | | - */ |
169 | | - private function isCacheKeySafe(array $context): bool |
170 | | - { |
171 | | - if (!isset($context['resource_class']) || !$this->resourceClassResolver->isResourceClass($context['resource_class'])) { |
172 | | - return false; |
173 | | - } |
174 | | - $resourceClass = $this->resourceClassResolver->getResourceClass(null, $context['resource_class']); |
175 | | - if (isset($this->safeCacheKeysCache[$resourceClass])) { |
176 | | - return $this->safeCacheKeysCache[$resourceClass]; |
177 | | - } |
178 | | - $options = $this->getFactoryOptions($context); |
179 | | - $propertyNames = $this->propertyNameCollectionFactory->create($resourceClass, $options); |
180 | | - |
181 | | - $this->safeCacheKeysCache[$resourceClass] = true; |
182 | | - foreach ($propertyNames as $propertyName) { |
183 | | - $propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $propertyName, $options); |
184 | | - if (null !== $propertyMetadata->getSecurity()) { |
185 | | - $this->safeCacheKeysCache[$resourceClass] = false; |
186 | | - break; |
187 | | - } |
188 | | - } |
189 | | - |
190 | | - return $this->safeCacheKeysCache[$resourceClass]; |
191 | | - } |
192 | 154 | } |
0 commit comments