-
-
Notifications
You must be signed in to change notification settings - Fork 512
Ensure proxy-manager is not used when native lazy objects are enabled #2884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
55d2cfd
5b7f434
211488a
a311fe1
673e6dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -451,29 +451,18 @@ public function hydrate(object $document, array $data, array $hints = []): array | |
| } | ||
| } | ||
|
|
||
| // Skip initialization to not load any object data | ||
| if (PHP_VERSION_ID >= 80400) { | ||
| $metadata->reflClass->markLazyObjectAsInitialized($document); | ||
| } | ||
|
|
||
| if ($document instanceof InternalProxy) { | ||
| // Skip initialization to not load any object data | ||
| $document->__setInitialized(true); | ||
| } | ||
|
|
||
| // Support for legacy proxy-manager-lts | ||
| if ($document instanceof GhostObjectInterface && $document->getProxyInitializer() !== null) { | ||
| // Inject an empty initialiser to not load any object data | ||
| $document->setProxyInitializer(static function ( | ||
| GhostObjectInterface $ghostObject, | ||
| string $method, // we don't care | ||
| array $parameters, // we don't care | ||
| &$initializer, | ||
| array $properties, // we currently do not use this | ||
| ): bool { | ||
| $initializer = null; | ||
|
|
||
| return true; | ||
| }); | ||
|
Comment on lines
-464
to
-476
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to set the initializer to |
||
| if ($document instanceof GhostObjectInterface) { | ||
| $document->setProxyInitializer(null); | ||
| } | ||
|
|
||
| $data = $this->getHydratorFor($metadata->name)->hydrate($document, $data, $hints); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,7 +146,7 @@ private function skippedFieldsFqns(ClassMetadata $metadata): array | |
| $skippedFieldsFqns = []; | ||
|
|
||
| foreach ($metadata->getIdentifierFieldNames() as $idField) { | ||
| $skippedFieldsFqns[] = $this->propertyFqcn($metadata->getReflectionProperty($idField)); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove usage of the deprecated |
||
| $skippedFieldsFqns[] = $this->propertyFqcn($metadata->getPropertyAccessor($idField)->getUnderlyingReflector()); | ||
| } | ||
|
|
||
| foreach ($metadata->getReflectionClass()->getProperties() as $property) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ class Tag | |
| public ?string $id; | ||
|
|
||
| #[ODM\Field] | ||
| public readonly string $name; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the |
||
| public string $name; | ||
|
|
||
| /** @var Collection<int, BlogPost> */ | ||
| #[ODM\ReferenceMany(targetDocument: BlogPost::class, mappedBy: 'tags')] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Tests\Functional; | ||
|
|
||
| use Doctrine\ODM\MongoDB\Mapping\Annotations\Document; | ||
| use Doctrine\ODM\MongoDB\Mapping\Annotations\Field; | ||
| use Doctrine\ODM\MongoDB\Mapping\Annotations\Id; | ||
| use Doctrine\ODM\MongoDB\Mapping\Annotations\ReferenceOne; | ||
| use Doctrine\ODM\MongoDB\Tests\BaseTestCase; | ||
|
|
||
| class ReadOnlyPropertiesTest extends BaseTestCase | ||
| { | ||
| public function testReadOnlyDocument(): void | ||
| { | ||
| $configuration = $this->dm->getConfiguration(); | ||
| if (! $configuration->isNativeLazyObjectEnabled() && ! $configuration->isLazyGhostObjectEnabled()) { | ||
| $this->markTestSkipped('Read-only properties are not supported by the legacy Proxy Manager. https://github.com/FriendsOfPHP/proxy-manager-lts/issues/26'); | ||
GromNaN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| $document = new ReadOnlyProperties('Test Name'); | ||
| $document->onlyRead = new ReadOnlyProperties('Nested Name'); | ||
| $this->dm->persist($document); | ||
| $this->dm->persist($document->onlyRead); | ||
| $this->dm->flush(); | ||
| $this->dm->clear(); | ||
|
|
||
| $document = $this->dm->getRepository(ReadOnlyProperties::class)->find($document->id); | ||
| $this->assertEquals('Test Name', $document->name); | ||
| $this->assertEquals('Nested Name', $document->onlyRead->name); | ||
| } | ||
| } | ||
|
|
||
| #[Document] | ||
| class ReadOnlyProperties | ||
| { | ||
| #[Id] | ||
| public readonly string $id; // @phpstan-ignore property.uninitializedReadonly (initialized by reflection) | ||
|
|
||
| #[Field] | ||
| public readonly string $name; | ||
|
|
||
| #[ReferenceOne(targetDocument: self::class)] | ||
| public ?self $onlyRead; | ||
|
|
||
| public function __construct(string $name) | ||
| { | ||
| $this->name = $name; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was setting
lazyGhostObject = truewhen callingsetUseNativeLazyObject(false), which is not expected.