|
18 | 18 | use ApiPlatform\Metadata\Exception\OperationNotFoundException; |
19 | 19 | use ApiPlatform\Metadata\GetCollection; |
20 | 20 | use ApiPlatform\Metadata\IriConverterInterface; |
| 21 | +use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; |
21 | 22 | use ApiPlatform\Metadata\ResourceClassResolverInterface; |
22 | 23 | use ApiPlatform\Metadata\UrlGeneratorInterface; |
23 | 24 | use ApiPlatform\Metadata\Util\ClassInfoTrait; |
@@ -48,9 +49,10 @@ final class PurgeHttpCacheListener |
48 | 49 | public function __construct(private readonly PurgerInterface $purger, |
49 | 50 | private readonly IriConverterInterface $iriConverter, |
50 | 51 | private readonly ResourceClassResolverInterface $resourceClassResolver, |
| 52 | + private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, |
51 | 53 | ?PropertyAccessorInterface $propertyAccessor = null, |
52 | 54 | private readonly ?ObjectMapperInterface $objectMapper = null, |
53 | | - private readonly ?ObjectMapperMetadataFactoryInterface $objectMapperMetadata = null) |
| 55 | + private readonly ?ObjectMapperMetadataFactoryInterface $objectMapperMetadata = null, ) |
54 | 56 | { |
55 | 57 | $this->propertyAccessor = $propertyAccessor ?? PropertyAccess::createPropertyAccessor(); |
56 | 58 | } |
@@ -128,8 +130,17 @@ private function gatherResourceAndItemTags(object $entity, bool $purgeItem): voi |
128 | 130 |
|
129 | 131 | foreach ($resources as $resource) { |
130 | 132 | try { |
131 | | - $iri = $this->iriConverter->getIriFromResource($resource, UrlGeneratorInterface::ABS_PATH, new GetCollection()); |
132 | | - $this->tags[$iri] = $iri; |
| 133 | + // Here we need to loop on all GetCollection Operations, there can be multiple for a single resource class |
| 134 | + $resourceClass = $this->resourceClassResolver->getResourceClass($resource); |
| 135 | + $resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass); |
| 136 | + foreach ($resourceMetadataCollection as $resourceMetadata) { |
| 137 | + foreach ($resourceMetadata->getOperations() as $operation) { |
| 138 | + if ($operation instanceof GetCollection) { |
| 139 | + $iri = $this->iriConverter->getIriFromResource($resource, UrlGeneratorInterface::ABS_PATH, $operation); |
| 140 | + $this->tags[$iri] = $iri; |
| 141 | + } |
| 142 | + } |
| 143 | + } |
133 | 144 |
|
134 | 145 | if ($purgeItem) { |
135 | 146 | $this->addTagForItem($entity); |
|
0 commit comments