Skip to content

Commit

Permalink
fix(doctrine): remove usage of deprecated ClassUtils in PurgeHttpCach…
Browse files Browse the repository at this point in the history
…eListener for Doctrine ORM 3 (#6331)

Co-authored-by: Antoine Bluchet <soyuka@users.noreply.github.com>
  • Loading branch information
wtfzdotnet and soyuka committed Apr 27, 2024
1 parent c083af3 commit 9cd597f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Doctrine/EventListener/PurgeHttpCacheListener.php
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(\get_class($eventArgs->getObject()))->getAssociationMappings();

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($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)) {
Expand Down

0 comments on commit 9cd597f

Please sign in to comment.