@@ -154,15 +154,31 @@ protected function __construct(?Client $client = null, ?Configuration $config =
154154 $ this ->config ->getDriverOptions (),
155155 );
156156
157- $ this ->classNameResolver = $ this ->config ->isLazyGhostObjectEnabled ()
158- ? new CachingClassNameResolver (new LazyGhostProxyClassNameResolver ())
159- : new CachingClassNameResolver (new ProxyManagerClassNameResolver ($ this ->config ));
157+ if ($ this ->config ->isNativeLazyObjectEnabled ()) {
158+ $ this ->classNameResolver = new class implements ClassNameResolver, ProxyClassNameResolver {
159+ public function getRealClass (string $ class ): string
160+ {
161+ return $ class ;
162+ }
163+
164+ public function resolveClassName (string $ className ): string
165+ {
166+ return $ className ;
167+ }
168+ };
169+ } elseif ($ this ->config ->isLazyGhostObjectEnabled ()) {
170+ $ this ->classNameResolver = new CachingClassNameResolver (new LazyGhostProxyClassNameResolver ());
171+ } else {
172+ $ this ->classNameResolver = new CachingClassNameResolver (new ProxyManagerClassNameResolver ($ this ->config ));
173+ }
160174
161175 $ metadataFactoryClassName = $ this ->config ->getClassMetadataFactoryName ();
162176 $ this ->metadataFactory = new $ metadataFactoryClassName ();
163177 $ this ->metadataFactory ->setDocumentManager ($ this );
164178 $ this ->metadataFactory ->setConfiguration ($ this ->config );
165- $ this ->metadataFactory ->setProxyClassNameResolver ($ this ->classNameResolver );
179+ if (! $ this ->config ->isNativeLazyObjectEnabled ()) {
180+ $ this ->metadataFactory ->setProxyClassNameResolver ($ this ->classNameResolver );
181+ }
166182
167183 $ cacheDriver = $ this ->config ->getMetadataCache ();
168184 if ($ cacheDriver ) {
@@ -296,10 +312,14 @@ public function getSchemaManager(): SchemaManager
296312 /**
297313 * Returns the class name resolver which is used to resolve real class names for proxy objects.
298314 *
299- * @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.
300316 */
301317 public function getClassNameResolver (): ClassNameResolver
302318 {
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+
303323 return $ this ->classNameResolver ;
304324 }
305325
0 commit comments