Skip to content

Commit

Permalink
Fix the PurgeHttpCacheListener on doctrine 3
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Apr 22, 2024
1 parent 50c738c commit 7aaafa1
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Doctrine/EventListener/PurgeHttpCacheListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use ApiPlatform\Metadata\ResourceClassResolverInterface;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use ApiPlatform\Metadata\Util\ClassInfoTrait;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
Expand Down Expand Up @@ -60,7 +59,7 @@ public function preUpdate(PreUpdateEventArgs $eventArgs): void
$changeSet = $eventArgs->getEntityChangeSet();
// @phpstan-ignore-next-line
$objectManager = method_exists($eventArgs, 'getObjectManager') ? $eventArgs->getObjectManager() : $eventArgs->getEntityManager();
$associationMappings = $objectManager->getClassMetadata(ClassUtils::getClass($eventArgs->getObject()))->getAssociationMappings();
$associationMappings = $objectManager->getClassMetadata($objectManager->getClassMetadata(get_class($entity))->getName())->getAssociationMappings();

Check failure on line 62 in src/Doctrine/EventListener/PurgeHttpCacheListener.php

View workflow job for this annotation

GitHub Actions / PHPStan (PHP 8.3)

Undefined variable: $entity

foreach ($changeSet as $key => $value) {
if (!isset($associationMappings[$key])) {
Expand Down Expand Up @@ -127,7 +126,7 @@ private function gatherResourceAndItemTags(object $entity, bool $purgeItem): voi

private function gatherRelationTags(EntityManagerInterface $em, object $entity): void
{
$associationMappings = $em->getClassMetadata(ClassUtils::getClass($entity))->getAssociationMappings();
$associationMappings = $em->getClassMetadata($em->getClassMetadata(get_class($entity))->getName())->getAssociationMappings();
/** @var array|AssociationMapping $associationMapping according to the version of doctrine orm */
foreach ($associationMappings as $property => $associationMapping) {
if ($associationMapping instanceof AssociationMapping && ($associationMapping->targetEntity ?? null) && !$this->resourceClassResolver->isResourceClass($associationMapping->targetEntity)) {
Expand Down

0 comments on commit 7aaafa1

Please sign in to comment.