From 9cd597f80d9eecafb28b4229a313ba9b9618bf8c Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 27 Apr 2024 22:24:16 +0200 Subject: [PATCH] fix(doctrine): remove usage of deprecated ClassUtils in PurgeHttpCacheListener for Doctrine ORM 3 (#6331) Co-authored-by: Antoine Bluchet --- src/Doctrine/EventListener/PurgeHttpCacheListener.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Doctrine/EventListener/PurgeHttpCacheListener.php b/src/Doctrine/EventListener/PurgeHttpCacheListener.php index 7aba69f65f..fa7b081e4d 100644 --- a/src/Doctrine/EventListener/PurgeHttpCacheListener.php +++ b/src/Doctrine/EventListener/PurgeHttpCacheListener.php @@ -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; @@ -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(\get_class($eventArgs->getObject()))->getAssociationMappings(); foreach ($changeSet as $key => $value) { if (!isset($associationMappings[$key])) { @@ -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($entity::class)->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)) {