Skip to content

Commit 0e2607d

Browse files
committed
Deprecate ClassMetadataFactoryInterface::getProxyClassNameResolver()
1 parent 5acb54f commit 0e2607d

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

src/DocumentManager.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ public function resolveClassName(string $className): string
176176
$this->metadataFactory = new $metadataFactoryClassName();
177177
$this->metadataFactory->setDocumentManager($this);
178178
$this->metadataFactory->setConfiguration($this->config);
179-
$this->metadataFactory->setProxyClassNameResolver($this->classNameResolver);
179+
if (! $this->config->isNativeLazyObjectEnabled()) {
180+
$this->metadataFactory->setProxyClassNameResolver($this->classNameResolver);
181+
}
180182

181183
$cacheDriver = $this->config->getMetadataCache();
182184
if ($cacheDriver) {
@@ -310,10 +312,14 @@ public function getSchemaManager(): SchemaManager
310312
/**
311313
* Returns the class name resolver which is used to resolve real class names for proxy objects.
312314
*
313-
* @deprecated Fetch metadata for any class string (e.g. proxy object class) and read the class name from the metadata object
315+
* @deprecated Since 2.15, the use of proxy classes is deprecated and will be removed in Doctrine ODM 3.0.
314316
*/
315317
public function getClassNameResolver(): ClassNameResolver
316318
{
319+
if ($this->getConfiguration()->isNativeLazyObjectEnabled()) {
320+
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__);
321+
}
322+
317323
return $this->classNameResolver;
318324
}
319325

src/DocumentNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use const JSON_THROW_ON_ERROR;
1313

1414
/**
15-
* Class for exception when encountering proxy object that has
15+
* Class for exception when encountering a lazy object that has
1616
* an identifier that does not exist in the database.
1717
*/
1818
final class DocumentNotFoundException extends MongoDBException

src/Events.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private function __construct()
130130
public const onClear = 'onClear';
131131

132132
/**
133-
* The documentNotFound event occurs if a proxy object could not be found in
133+
* The documentNotFound event occurs if a lazy object could not be found in
134134
* the database.
135135
*/
136136
public const documentNotFound = 'documentNotFound';

src/Mapping/ClassMetadataFactoryInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public function setDocumentManager(DocumentManager $dm): void;
3535

3636
/**
3737
* Sets a resolver for real class names of a proxy.
38+
*
39+
* @deprecated This method is deprecated and will be removed in Doctrine ODM 3.0.
3840
*/
3941
public function setProxyClassNameResolver(ProxyClassNameResolver $resolver): void;
4042
}

tests/Tests/DocumentManagerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\ODM\MongoDB\Mapping\MappingException;
1515
use Doctrine\ODM\MongoDB\MongoDBException;
1616
use Doctrine\ODM\MongoDB\Proxy\Factory\ProxyFactory;
17+
use Doctrine\ODM\MongoDB\Proxy\Resolver\ClassNameResolver;
1718
use Doctrine\ODM\MongoDB\Query\Builder as QueryBuilder;
1819
use Doctrine\ODM\MongoDB\Query\FilterCollection;
1920
use Doctrine\ODM\MongoDB\SchemaManager;
@@ -34,6 +35,7 @@
3435
use MongoDB\BSON\ObjectId;
3536
use MongoDB\Client;
3637
use PHPUnit\Framework\Attributes\DataProvider;
38+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
3739
use RuntimeException;
3840
use stdClass;
3941

@@ -261,6 +263,13 @@ public function testGetClassNameForAssociationReturnsTargetDocumentWithNullData(
261263
$mapping = ClassMetadataTestUtil::getFieldMapping(['targetDocument' => User::class]);
262264
self::assertEquals(User::class, $this->dm->getClassNameForAssociation($mapping, null));
263265
}
266+
267+
#[IgnoreDeprecations]
268+
public function testGetClassNameResolver(): void
269+
{
270+
$resolver = $this->dm->getClassNameResolver();
271+
self::assertInstanceOf(ClassNameResolver::class, $resolver);
272+
}
264273
}
265274

266275
#[ODM\Document]

0 commit comments

Comments
 (0)