diff --git a/src/DocumentManager.php b/src/DocumentManager.php index f73be994d..2dfb67874 100644 --- a/src/DocumentManager.php +++ b/src/DocumentManager.php @@ -176,7 +176,9 @@ public function resolveClassName(string $className): string $this->metadataFactory = new $metadataFactoryClassName(); $this->metadataFactory->setDocumentManager($this); $this->metadataFactory->setConfiguration($this->config); - $this->metadataFactory->setProxyClassNameResolver($this->classNameResolver); + if (! $this->config->isNativeLazyObjectEnabled()) { + $this->metadataFactory->setProxyClassNameResolver($this->classNameResolver); + } $cacheDriver = $this->config->getMetadataCache(); if ($cacheDriver) { @@ -310,10 +312,14 @@ public function getSchemaManager(): SchemaManager /** * Returns the class name resolver which is used to resolve real class names for proxy objects. * - * @deprecated Fetch metadata for any class string (e.g. proxy object class) and read the class name from the metadata object + * @deprecated Since 2.15, the use of proxy classes is deprecated and will be removed in Doctrine ODM 3.0. */ public function getClassNameResolver(): ClassNameResolver { + if ($this->getConfiguration()->isNativeLazyObjectEnabled()) { + trigger_deprecation('doctrine/mongodb-odm', '2.15', 'The %s() method is deprecated and will be removed in Doctrine ODM 3.0. There are no proxy classes when using native lazy objects', __METHOD__); + } + return $this->classNameResolver; } diff --git a/src/DocumentNotFoundException.php b/src/DocumentNotFoundException.php index 310cac6de..a32c9965f 100644 --- a/src/DocumentNotFoundException.php +++ b/src/DocumentNotFoundException.php @@ -12,7 +12,7 @@ use const JSON_THROW_ON_ERROR; /** - * Class for exception when encountering proxy object that has + * Class for exception when encountering a lazy object that has * an identifier that does not exist in the database. */ final class DocumentNotFoundException extends MongoDBException diff --git a/src/Events.php b/src/Events.php index bbeb6e4d8..b19c7f3af 100644 --- a/src/Events.php +++ b/src/Events.php @@ -130,7 +130,7 @@ private function __construct() public const onClear = 'onClear'; /** - * The documentNotFound event occurs if a proxy object could not be found in + * The documentNotFound event occurs if a lazy object could not be found in * the database. */ public const documentNotFound = 'documentNotFound'; diff --git a/src/Mapping/ClassMetadataFactoryInterface.php b/src/Mapping/ClassMetadataFactoryInterface.php index 3c543e3cc..bacd47ec3 100644 --- a/src/Mapping/ClassMetadataFactoryInterface.php +++ b/src/Mapping/ClassMetadataFactoryInterface.php @@ -35,6 +35,8 @@ public function setDocumentManager(DocumentManager $dm): void; /** * Sets a resolver for real class names of a proxy. + * + * @deprecated This method is deprecated and will be removed in Doctrine ODM 3.0. */ public function setProxyClassNameResolver(ProxyClassNameResolver $resolver): void; } diff --git a/tests/Tests/DocumentManagerTest.php b/tests/Tests/DocumentManagerTest.php index 832037e53..a23f5612d 100644 --- a/tests/Tests/DocumentManagerTest.php +++ b/tests/Tests/DocumentManagerTest.php @@ -14,6 +14,7 @@ use Doctrine\ODM\MongoDB\Mapping\MappingException; use Doctrine\ODM\MongoDB\MongoDBException; use Doctrine\ODM\MongoDB\Proxy\Factory\ProxyFactory; +use Doctrine\ODM\MongoDB\Proxy\Resolver\ClassNameResolver; use Doctrine\ODM\MongoDB\Query\Builder as QueryBuilder; use Doctrine\ODM\MongoDB\Query\FilterCollection; use Doctrine\ODM\MongoDB\SchemaManager; @@ -34,6 +35,7 @@ use MongoDB\BSON\ObjectId; use MongoDB\Client; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use RuntimeException; use stdClass; @@ -261,6 +263,13 @@ public function testGetClassNameForAssociationReturnsTargetDocumentWithNullData( $mapping = ClassMetadataTestUtil::getFieldMapping(['targetDocument' => User::class]); self::assertEquals(User::class, $this->dm->getClassNameForAssociation($mapping, null)); } + + #[IgnoreDeprecations] + public function testGetClassNameResolver(): void + { + $resolver = $this->dm->getClassNameResolver(); + self::assertInstanceOf(ClassNameResolver::class, $resolver); + } } #[ODM\Document]