Skip to content

Conversation

@GromNaN
Copy link
Member

@GromNaN GromNaN commented Nov 14, 2025

I was wrong in #940 (comment).

Fix the interface that identifies the lazy objects.

Note that Doctrine\Persistence\Mapping\ProxyClassNameResolver should be used by Doctrine\Persistence\AbstractManagerRegistry instead of repeating the same logic.

@GromNaN GromNaN requested review from jmikola and paulinevos and removed request for jmikola November 14, 2025 15:46
@GromNaN GromNaN added the bug label Nov 14, 2025
@GromNaN GromNaN added this to the 5.5.0 milestone Nov 14, 2025
@GromNaN GromNaN requested a review from jmikola November 14, 2025 15:46
@GromNaN GromNaN force-pushed the fix-proxy-interface branch from 95dbccc to ca1909c Compare November 14, 2025 15:48
@GromNaN GromNaN requested a review from alcaeus November 14, 2025 16:08

$container->getDefinition('doctrine_mongodb')
->setArgument(5, $config['enable_lazy_ghost_objects'] ? LazyLoadingInterface::class : Proxy::class);
->setArgument(5, $config['enable_lazy_ghost_objects'] ? Proxy::class : LazyLoadingInterface::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading #940 (comment) I'm still confused. These aren't the best class names. Is it worth adding a block comment above this to explain?

I went so far as to look at https://github.com/FriendsOfPHP/proxy-manager-lts/blob/1.x/src/ProxyManager/Proxy/LazyLoadingInterface.php and it's not even clear from that file.

Copy link
Member Author

@GromNaN GromNaN Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interfaces are used to get the parent class when looking for a class metadata from a proxy class name.
https://github.com/doctrine/persistence/blob/00bd9ccc1f9c6a74fc2dc557313869acd1998cba/src/AbstractManagerRegistry.php#L135

$loader->load([$config], $container);
}

#[DataProvider('provideLazyObjectConfigurations')]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does PHPStan want you to annotate array $config as an iterable of array shapes? I don't think that's necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the @phpstan-type


if (PHP_VERSION_ID >= 80400) {
yield 'Native Lazy Objects' => [
['enable_lazy_ghost_objects' => false, 'enable_native_lazy_objects' => true],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you test specifying true for both options? I assume enable_native_lazy_objects might take precedence, but would understand if they are mutually exclusive and should throw.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable_native_lazy_objects has priority over enable_lazy_ghost_objects. I don't test which lazy object implementation is used here, only overriding both default values since they are dynamically set depending of the PHP and ODM versions.

self::assertInstanceOf(ManagerRegistry::class, $registry);
self::assertInstanceOf(DocumentManager::class, $dm);

// Create a lazy object
Copy link
Member

@jmikola jmikola Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider a bigger comment that explains the last assertion on the DM registry is actually pertinent to testing the 5th argument (and your bug fix).

Assertion messages also work fine.

@GromNaN GromNaN force-pushed the fix-proxy-interface branch from 07663ae to fd608c2 Compare November 14, 2025 17:03
@GromNaN GromNaN merged commit e11ebf3 into doctrine:5.5.x Nov 14, 2025
10 checks passed
@GromNaN GromNaN deleted the fix-proxy-interface branch November 14, 2025 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants