Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/DocumentNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions src/Mapping/ClassMetadataFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
9 changes: 9 additions & 0 deletions tests/Tests/DocumentManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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]
Expand Down