Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
service('api_platform.http_cache.purger'),
service('api_platform.iri_converter'),
service('api_platform.resource_class_resolver'),
service('api_platform.metadata.resource.metadata_collection_factory'),
service('api_platform.property_accessor'),
service('api_platform.object_mapper')->nullOnInvalid(),
service('api_platform.object_mapper.metadata_factory')->nullOnInvalid(),
Expand Down
17 changes: 14 additions & 3 deletions src/Symfony/Doctrine/EventListener/PurgeHttpCacheListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use ApiPlatform\Metadata\Exception\OperationNotFoundException;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\IriConverterInterface;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Metadata\ResourceClassResolverInterface;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use ApiPlatform\Metadata\Util\ClassInfoTrait;
Expand Down Expand Up @@ -48,9 +49,10 @@ final class PurgeHttpCacheListener
public function __construct(private readonly PurgerInterface $purger,
private readonly IriConverterInterface $iriConverter,
private readonly ResourceClassResolverInterface $resourceClassResolver,
private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for bc we can't put an argument in the middle like this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, didn't think about that, i'll move it to the end.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to make it nullable , should i then handle the case where it's null with a fallback to what's currently done ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me have a look as maybe that we need to do that differently?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

?PropertyAccessorInterface $propertyAccessor = null,
private readonly ?ObjectMapperInterface $objectMapper = null,
private readonly ?ObjectMapperMetadataFactoryInterface $objectMapperMetadata = null)
private readonly ?ObjectMapperMetadataFactoryInterface $objectMapperMetadata = null, )
{
$this->propertyAccessor = $propertyAccessor ?? PropertyAccess::createPropertyAccessor();
}
Expand Down Expand Up @@ -128,8 +130,17 @@ private function gatherResourceAndItemTags(object $entity, bool $purgeItem): voi

foreach ($resources as $resource) {
try {
$iri = $this->iriConverter->getIriFromResource($resource, UrlGeneratorInterface::ABS_PATH, new GetCollection());
$this->tags[$iri] = $iri;
// Here we need to loop on all GetCollection Operations, there can be multiple for a single resource class
$resourceClass = $this->resourceClassResolver->getResourceClass($resource);
$resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass);
foreach ($resourceMetadataCollection as $resourceMetadata) {
foreach ($resourceMetadata->getOperations() as $operation) {
if ($operation instanceof GetCollection) {
$iri = $this->iriConverter->getIriFromResource($resource, UrlGeneratorInterface::ABS_PATH, $operation);
$this->tags[$iri] = $iri;
}
}
}

if ($purgeItem) {
$this->addTagForItem($entity);
Expand Down
Loading
Loading