From 7ca6e55d02b45f19386c76eb1ed778416c441505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 12 Oct 2023 21:29:04 +0200 Subject: [PATCH] Implement proxy name resolver It is important to have the same implementation as used in doctrine/persistence without relying on copy/paste. --- lib/Doctrine/ORM/AbstractQuery.php | 3 +- lib/Doctrine/ORM/Cache/DefaultCache.php | 10 ++++--- .../ORM/Cache/DefaultEntityHydrator.php | 3 +- .../AbstractCollectionPersister.php | 20 +++++++------ .../ReadOnlyCachedCollectionPersister.php | 3 +- .../Entity/AbstractEntityPersister.php | 24 ++++++++-------- .../Entity/ReadOnlyCachedEntityPersister.php | 3 +- lib/Doctrine/ORM/Configuration.php | 15 ++++++++++ lib/Doctrine/ORM/EntityManager.php | 3 +- .../ORM/Mapping/ClassMetadataFactory.php | 2 ++ .../Entity/BasicEntityPersister.php | 18 ++++++------ ....php => DefaultProxyClassNameResolver.php} | 28 +++++++------------ phpcs.xml.dist | 2 +- psalm-baseline.xml | 4 +-- .../ORM/Functional/PostLoadEventTest.php | 8 ++++-- .../ORM/Functional/ReferenceProxyTest.php | 3 +- ... => DefaultProxyClassNameResolverTest.php} | 11 ++++---- 17 files changed, 88 insertions(+), 72 deletions(-) rename lib/Doctrine/ORM/Proxy/{ClassUtils.php => DefaultProxyClassNameResolver.php} (62%) rename tests/Doctrine/Tests/Proxy/{ClassUtilsTest.php => DefaultProxyClassNameResolverTest.php} (75%) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index f4f2eaabb59..c616c08191b 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -16,7 +16,6 @@ use Doctrine\ORM\Cache\TimestampCacheKey; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\MappingException as ORMMappingException; -use Doctrine\ORM\Proxy\ClassUtils; use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\Query\QueryException; use Doctrine\ORM\Query\ResultSetMapping; @@ -379,7 +378,7 @@ public function processParameterValue(mixed $value): mixed } try { - $class = ClassUtils::getClass($value); + $class = $this->em->getConfiguration()->getProxyClassNameResolver()->resolveClass($value); $value = $this->em->getUnitOfWork()->getSingleIdentifierValue($value); if ($value === null) { diff --git a/lib/Doctrine/ORM/Cache/DefaultCache.php b/lib/Doctrine/ORM/Cache/DefaultCache.php index c877ad38b1c..6767ecb1da1 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultCache.php @@ -9,7 +9,7 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\ORMInvalidArgumentException; -use Doctrine\ORM\Proxy\ClassUtils; +use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver; use Doctrine\ORM\UnitOfWork; use function is_array; @@ -22,6 +22,7 @@ class DefaultCache implements Cache { private readonly UnitOfWork $uow; private readonly CacheFactory $cacheFactory; + private readonly DefaultProxyClassNameResolver $proxyClassNameResolver; /** * @var QueryCache[] @@ -34,10 +35,11 @@ class DefaultCache implements Cache public function __construct( private readonly EntityManagerInterface $em, ) { - $this->uow = $em->getUnitOfWork(); - $this->cacheFactory = $em->getConfiguration() + $this->uow = $em->getUnitOfWork(); + $this->cacheFactory = $em->getConfiguration() ->getSecondLevelCacheConfiguration() ->getCacheFactory(); + $this->proxyClassNameResolver = $em->getConfiguration()->getProxyClassNameResolver(); } public function getEntityCacheRegion(string $className): Region|null @@ -233,7 +235,7 @@ private function buildCollectionCacheKey( private function toIdentifierArray(ClassMetadata $metadata, mixed $identifier): array { if (is_object($identifier)) { - $class = ClassUtils::getClass($identifier); + $class = $this->proxyClassNameResolver->resolveClass($identifier); if ($this->em->getMetadataFactory()->hasMetadataFor($class)) { $identifier = $this->uow->getSingleIdentifierValue($identifier) ?? throw ORMInvalidArgumentException::invalidIdentifierBindingEntity($class); diff --git a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php index 69f020cafa8..dc26e0a33ae 100644 --- a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php +++ b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php @@ -6,7 +6,6 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Proxy\ClassUtils; use Doctrine\ORM\Query; use Doctrine\ORM\UnitOfWork; use Doctrine\ORM\Utility\IdentifierFlattener; @@ -97,7 +96,7 @@ public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, ob } if (! isset($assoc->id)) { - $targetClass = ClassUtils::getClass($data[$name]); + $targetClass = $this->em->getConfiguration()->getProxyClassNameResolver()->resolveClass($data[$name]); $targetId = $this->uow->getEntityIdentifier($data[$name]); $data[$name] = new AssociationCacheEntry($targetClass, $targetId); diff --git a/lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php b/lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php index ffb7f5568e6..22be87752c3 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php @@ -17,7 +17,7 @@ use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Persisters\Collection\CollectionPersister; -use Doctrine\ORM\Proxy\ClassUtils; +use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver; use Doctrine\ORM\UnitOfWork; use function array_values; @@ -37,6 +37,7 @@ abstract class AbstractCollectionPersister implements CachedCollectionPersister protected string $regionName; protected CollectionHydrator $hydrator; protected CacheLogger|null $cacheLogger; + protected DefaultProxyClassNameResolver $proxyClassNameResolver; public function __construct( protected CollectionPersister $persister, @@ -48,13 +49,14 @@ public function __construct( $cacheConfig = $configuration->getSecondLevelCacheConfiguration(); $cacheFactory = $cacheConfig->getCacheFactory(); - $this->regionName = $region->getName(); - $this->uow = $em->getUnitOfWork(); - $this->metadataFactory = $em->getMetadataFactory(); - $this->cacheLogger = $cacheConfig->getCacheLogger(); - $this->hydrator = $cacheFactory->buildCollectionHydrator($em, $association); - $this->sourceEntity = $em->getClassMetadata($association->sourceEntity); - $this->targetEntity = $em->getClassMetadata($association->targetEntity); + $this->regionName = $region->getName(); + $this->uow = $em->getUnitOfWork(); + $this->metadataFactory = $em->getMetadataFactory(); + $this->cacheLogger = $cacheConfig->getCacheLogger(); + $this->hydrator = $cacheFactory->buildCollectionHydrator($em, $association); + $this->sourceEntity = $em->getClassMetadata($association->sourceEntity); + $this->targetEntity = $em->getClassMetadata($association->targetEntity); + $this->proxyClassNameResolver = $configuration->getProxyClassNameResolver(); } public function getCacheRegion(): Region @@ -105,7 +107,7 @@ public function storeCollectionCache(CollectionCacheKey $key, Collection|array $ } $class = $this->targetEntity; - $className = ClassUtils::getClass($elements[$index]); + $className = $this->proxyClassNameResolver->resolveClass($elements[$index]); if ($className !== $this->targetEntity->name) { $class = $this->metadataFactory->getMetadataFor($className); diff --git a/lib/Doctrine/ORM/Cache/Persister/Collection/ReadOnlyCachedCollectionPersister.php b/lib/Doctrine/ORM/Cache/Persister/Collection/ReadOnlyCachedCollectionPersister.php index b9955b218ea..1e11410aa48 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Collection/ReadOnlyCachedCollectionPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Collection/ReadOnlyCachedCollectionPersister.php @@ -6,7 +6,6 @@ use Doctrine\ORM\Cache\Exception\CannotUpdateReadOnlyCollection; use Doctrine\ORM\PersistentCollection; -use Doctrine\ORM\Proxy\ClassUtils; class ReadOnlyCachedCollectionPersister extends NonStrictReadWriteCachedCollectionPersister { @@ -14,7 +13,7 @@ public function update(PersistentCollection $collection): void { if ($collection->isDirty() && $collection->getSnapshot()) { throw CannotUpdateReadOnlyCollection::fromEntityAndField( - ClassUtils::getClass($collection->getOwner()), + $this->proxyClassNameResolver->resolveClass($collection->getOwner()), $this->association->fieldName, ); } diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php index 62f32f491a0..da2be4d5dfa 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php @@ -22,7 +22,7 @@ use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Persisters\Entity\EntityPersister; -use Doctrine\ORM\Proxy\ClassUtils; +use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\UnitOfWork; @@ -35,6 +35,7 @@ abstract class AbstractEntityPersister implements CachedEntityPersister { protected UnitOfWork $uow; protected ClassMetadataFactory $metadataFactory; + protected DefaultProxyClassNameResolver $proxyClassNameResolver; /** @var mixed[] */ protected array $queuedCache = []; @@ -63,14 +64,15 @@ public function __construct( $cacheConfig = $configuration->getSecondLevelCacheConfiguration(); $cacheFactory = $cacheConfig->getCacheFactory(); - $this->cache = $em->getCache(); - $this->regionName = $region->getName(); - $this->uow = $em->getUnitOfWork(); - $this->metadataFactory = $em->getMetadataFactory(); - $this->cacheLogger = $cacheConfig->getCacheLogger(); - $this->timestampRegion = $cacheFactory->getTimestampRegion(); - $this->hydrator = $cacheFactory->buildEntityHydrator($em, $class); - $this->timestampKey = new TimestampCacheKey($this->class->rootEntityName); + $this->cache = $em->getCache(); + $this->regionName = $region->getName(); + $this->uow = $em->getUnitOfWork(); + $this->metadataFactory = $em->getMetadataFactory(); + $this->cacheLogger = $cacheConfig->getCacheLogger(); + $this->timestampRegion = $cacheFactory->getTimestampRegion(); + $this->hydrator = $cacheFactory->buildEntityHydrator($em, $class); + $this->timestampKey = new TimestampCacheKey($this->class->rootEntityName); + $this->proxyClassNameResolver = $configuration->getProxyClassNameResolver(); } public function addInsert(object $entity): void @@ -147,7 +149,7 @@ public function getEntityHydrator(): EntityHydrator public function storeEntityCache(object $entity, EntityCacheKey $key): bool { $class = $this->class; - $className = ClassUtils::getClass($entity); + $className = $this->proxyClassNameResolver->resolveClass($entity); if ($className !== $this->class->name) { $class = $this->metadataFactory->getMetadataFor($className); @@ -394,7 +396,7 @@ public function loadById(array $identifier, object|null $entity = null): object| } $class = $this->class; - $className = ClassUtils::getClass($entity); + $className = $this->proxyClassNameResolver->resolveClass($entity); if ($className !== $this->class->name) { $class = $this->metadataFactory->getMetadataFor($className); diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/ReadOnlyCachedEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/ReadOnlyCachedEntityPersister.php index 5ba2e4bf40f..cf7db778bbe 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/ReadOnlyCachedEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/ReadOnlyCachedEntityPersister.php @@ -5,7 +5,6 @@ namespace Doctrine\ORM\Cache\Persister\Entity; use Doctrine\ORM\Cache\Exception\CannotUpdateReadOnlyEntity; -use Doctrine\ORM\Proxy\ClassUtils; /** * Specific read-only region entity persister @@ -14,6 +13,6 @@ class ReadOnlyCachedEntityPersister extends NonStrictReadWriteCachedEntityPersis { public function update(object $entity): void { - throw CannotUpdateReadOnlyEntity::fromEntity(ClassUtils::getClass($entity)); + throw CannotUpdateReadOnlyEntity::fromEntity($this->proxyClassNameResolver->resolveClass($entity)); } } diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 63c39d42de2..5860d465319 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -17,6 +17,7 @@ use Doctrine\ORM\Mapping\NamingStrategy; use Doctrine\ORM\Mapping\QuoteStrategy; use Doctrine\ORM\Mapping\TypedFieldMapper; +use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver; use Doctrine\ORM\Proxy\ProxyFactory; use Doctrine\ORM\Query\AST\Functions\FunctionNode; use Doctrine\ORM\Query\Filter\SQLFilter; @@ -108,6 +109,20 @@ public function setProxyNamespace(string $ns): void $this->attributes['proxyNamespace'] = $ns; } + /** + * Gets the proxy class name resolver. + * + * @internal + */ + public function getProxyClassNameResolver(): DefaultProxyClassNameResolver + { + if (! isset($this->attributes['proxyClassNameResolver'])) { + $this->attributes['proxyClassNameResolver'] = new DefaultProxyClassNameResolver(); + } + + return $this->attributes['proxyClassNameResolver']; + } + /** * Sets the cache driver implementation that is used for metadata caching. * diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index f424c4cf3b1..3ae611f70a4 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -18,7 +18,6 @@ use Doctrine\ORM\Internal\Hydration\AbstractHydrator; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; -use Doctrine\ORM\Proxy\ClassUtils; use Doctrine\ORM\Proxy\ProxyFactory; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\FilterCollection; @@ -281,7 +280,7 @@ public function find($className, mixed $id, LockMode|int|null $lockMode = null, foreach ($id as $i => $value) { if (is_object($value)) { - $className = ClassUtils::getClass($value); + $className = $this->getConfiguration()->getProxyClassNameResolver()->resolveClass($value); if ($this->metadataFactory->hasMetadataFor($className)) { $id[$i] = $this->unitOfWork->getSingleIdentifierValue($value); diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index ad782108a0b..f5e72a73c78 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -61,6 +61,8 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory public function setEntityManager(EntityManagerInterface $em): void { + parent::setProxyClassNameResolver($em->getConfiguration()->getProxyClassNameResolver()); + $this->em = $em; } diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 077637b1b5a..a7a07e842d5 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -30,7 +30,7 @@ use Doctrine\ORM\Persisters\Exception\UnrecognizedField; use Doctrine\ORM\Persisters\SqlExpressionVisitor; use Doctrine\ORM\Persisters\SqlValueVisitor; -use Doctrine\ORM\Proxy\ClassUtils; +use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver; use Doctrine\ORM\Query; use Doctrine\ORM\Query\QueryException; use Doctrine\ORM\Query\ResultSetMapping; @@ -168,6 +168,7 @@ class BasicEntityPersister implements EntityPersister protected CachedPersisterContext $currentPersisterContext; private readonly CachedPersisterContext $limitsHandlingContext; private readonly CachedPersisterContext $noLimitsContext; + private readonly DefaultProxyClassNameResolver $proxyClassNameResolver; /** * Initializes a new BasicEntityPersister that uses the given EntityManager @@ -179,16 +180,17 @@ public function __construct( protected EntityManagerInterface $em, protected ClassMetadata $class, ) { - $this->conn = $em->getConnection(); - $this->platform = $this->conn->getDatabasePlatform(); - $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy(); - $this->identifierFlattener = new IdentifierFlattener($em->getUnitOfWork(), $em->getMetadataFactory()); - $this->noLimitsContext = $this->currentPersisterContext = new CachedPersisterContext( + $this->conn = $em->getConnection(); + $this->platform = $this->conn->getDatabasePlatform(); + $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy(); + $this->proxyClassNameResolver = $em->getConfiguration()->getProxyClassNameResolver(); + $this->identifierFlattener = new IdentifierFlattener($em->getUnitOfWork(), $em->getMetadataFactory()); + $this->noLimitsContext = $this->currentPersisterContext = new CachedPersisterContext( $class, new Query\ResultSetMapping(), false, ); - $this->limitsHandlingContext = new CachedPersisterContext( + $this->limitsHandlingContext = new CachedPersisterContext( $class, new Query\ResultSetMapping(), true, @@ -1940,7 +1942,7 @@ private function getIndividualValue(mixed $value): array return [$value->value]; } - $valueClass = ClassUtils::getClass($value); + $valueClass = $this->proxyClassNameResolver->resolveClass($value); if ($this->em->getMetadataFactory()->isTransient($valueClass)) { return [$value]; diff --git a/lib/Doctrine/ORM/Proxy/ClassUtils.php b/lib/Doctrine/ORM/Proxy/DefaultProxyClassNameResolver.php similarity index 62% rename from lib/Doctrine/ORM/Proxy/ClassUtils.php rename to lib/Doctrine/ORM/Proxy/DefaultProxyClassNameResolver.php index 4cdda47f1a1..a7c3421bbc8 100644 --- a/lib/Doctrine/ORM/Proxy/ClassUtils.php +++ b/lib/Doctrine/ORM/Proxy/DefaultProxyClassNameResolver.php @@ -4,6 +4,7 @@ namespace Doctrine\ORM\Proxy; +use Doctrine\Persistence\Mapping\ProxyClassNameResolver; use Doctrine\Persistence\Proxy; use function get_class; @@ -16,18 +17,23 @@ * * @internal */ -final class ClassUtils +class DefaultProxyClassNameResolver implements ProxyClassNameResolver { /** - * Gets the real class name of a class name that could be a proxy. + * Gets the real class name of an object (even if its a proxy). * - * @param class-string>|class-string $className + * @param Proxy|T $object * * @return class-string * * @template T of object */ - private static function getRealClass(string $className): string + public function resolveClass(object $object): string + { + return $this->resolveClassName(get_class($object)); + } + + public function resolveClassName(string $className): string { $pos = strrpos($className, '\\' . Proxy::MARKER . '\\'); @@ -37,18 +43,4 @@ private static function getRealClass(string $className): string return substr($className, $pos + Proxy::MARKER_LENGTH + 2); } - - /** - * Gets the real class name of an object (even if its a proxy). - * - * @param Proxy|T $object - * - * @return class-string - * - * @template T of object - */ - public static function getClass(object $object): string - { - return self::getRealClass(get_class($object)); - } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index d6cd03474ce..a6cacb68a75 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -204,7 +204,7 @@ - tests/Doctrine/Tests/Proxy/ClassUtilsTest.php + tests/Doctrine/Tests/Proxy/DefaultProxyClassNameResolverTest.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 8f3739a8847..92600ce558c 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -742,13 +742,13 @@ require $file - + $className substr($className, $pos + Proxy::MARKER_LENGTH + 2) - ]]> + string diff --git a/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php b/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php index b0f429385ba..1112e697e37 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php @@ -4,9 +4,9 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Event\PostLoadEventArgs; use Doctrine\ORM\Events; -use Doctrine\ORM\Proxy\ClassUtils; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsEmail; use Doctrine\Tests\Models\CMS\CmsPhonenumber; @@ -15,6 +15,8 @@ use PHPUnit\Framework\Attributes\Group; use RuntimeException; +use function assert; + class PostLoadEventTest extends OrmFunctionalTestCase { private int|null $userId = null; @@ -281,7 +283,9 @@ class PostLoadListenerLoadEntityInEventHandler public function postLoad(PostLoadEventArgs $event): void { $object = $event->getObject(); - $class = ClassUtils::getClass($object); + $om = $event->getObjectManager(); + assert($om instanceof EntityManagerInterface); + $class = $om->getConfiguration()->getProxyClassNameResolver()->resolveClass($object); if (! isset($this->firedByClasses[$class])) { $this->firedByClasses[$class] = 1; } else { diff --git a/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php b/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php index f692a3d0ff1..5e47ee90c0d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php @@ -5,7 +5,6 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Proxy\Proxy as CommonProxy; -use Doctrine\ORM\Proxy\ClassUtils; use Doctrine\ORM\Proxy\InternalProxy; use Doctrine\Tests\Models\Company\CompanyAuction; use Doctrine\Tests\Models\ECommerce\ECommerceProduct; @@ -227,7 +226,7 @@ public function testCommonPersistenceProxy(): void $entity = $this->_em->getReference(ECommerceProduct::class, $id); assert($entity instanceof ECommerceProduct); - $className = ClassUtils::getClass($entity); + $className = $this->_em->getConfiguration()->getProxyClassNameResolver()->resolveClass($entity); self::assertInstanceOf(InternalProxy::class, $entity); self::assertTrue($this->isUninitializedObject($entity)); diff --git a/tests/Doctrine/Tests/Proxy/ClassUtilsTest.php b/tests/Doctrine/Tests/Proxy/DefaultProxyClassNameResolverTest.php similarity index 75% rename from tests/Doctrine/Tests/Proxy/ClassUtilsTest.php rename to tests/Doctrine/Tests/Proxy/DefaultProxyClassNameResolverTest.php index 81892a9894a..c0f41081fd0 100644 --- a/tests/Doctrine/Tests/Proxy/ClassUtilsTest.php +++ b/tests/Doctrine/Tests/Proxy/DefaultProxyClassNameResolverTest.php @@ -6,18 +6,18 @@ { - use Doctrine\ORM\Proxy\ClassUtils; + use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; - class ClassUtilsTest extends TestCase + class DefaultProxyClassNameResolverTest extends TestCase { /** @return list */ public static function dataGetClass(): iterable { return [ [\stdClass::class, \stdClass::class], - [ClassUtils::class, ClassUtils::class], + [DefaultProxyClassNameResolver::class, DefaultProxyClassNameResolver::class], [ 'MyProject\Proxies\__CG__\stdClass', \stdClass::class], [ 'MyProject\Proxies\__CG__\OtherProject\Proxies\__CG__\stdClass', \stdClass::class], [ 'MyProject\Proxies\__CG__\Doctrine\Tests\Proxy\ChildObject', ChildObject::class], @@ -27,8 +27,9 @@ public static function dataGetClass(): iterable #[DataProvider('dataGetClass')] public function testGetClass(string $className, string $expectedClassName): void { - $object = new $className(); - self::assertEquals($expectedClassName, ClassUtils::getClass($object)); + $object = new $className(); + $resolver = new DefaultProxyClassNameResolver(); + self::assertEquals($expectedClassName, $resolver->resolveClass($object)); } }