From 903a564d06dd5b12663cf4e4f237882a1a63f731 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 3 Apr 2024 22:29:34 +0200 Subject: [PATCH] add forward compatible method for https://github.com/doctrine/persistence/pull/334 --- .../ODM/PHPCR/Decorator/DocumentManagerDecorator.php | 5 +++++ lib/Doctrine/ODM/PHPCR/DocumentManager.php | 6 ++++++ .../ODM/PHPCR/Decorator/DocumentManagerDecoratorTest.php | 4 +++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ODM/PHPCR/Decorator/DocumentManagerDecorator.php b/lib/Doctrine/ODM/PHPCR/Decorator/DocumentManagerDecorator.php index ea5de65ff..98a6ca877 100644 --- a/lib/Doctrine/ODM/PHPCR/Decorator/DocumentManagerDecorator.php +++ b/lib/Doctrine/ODM/PHPCR/Decorator/DocumentManagerDecorator.php @@ -242,4 +242,9 @@ public function getDocumentId(object $document): string { return $this->wrapped->getDocumentId($document); } + + public function isUninitializedObject(mixed $value): bool + { + return $this->wrapped->isUninitializedObject($value); + } } diff --git a/lib/Doctrine/ODM/PHPCR/DocumentManager.php b/lib/Doctrine/ODM/PHPCR/DocumentManager.php index 18d9001fd..215b0ba59 100644 --- a/lib/Doctrine/ODM/PHPCR/DocumentManager.php +++ b/lib/Doctrine/ODM/PHPCR/DocumentManager.php @@ -19,6 +19,7 @@ use Doctrine\ODM\PHPCR\Translation\TranslationStrategy\ChildTranslationStrategy; use Doctrine\ODM\PHPCR\Translation\TranslationStrategy\TranslationStrategyInterface; use Doctrine\Persistence\ObjectRepository; +use Doctrine\Persistence\Proxy; use PHPCR\ItemNotFoundException; use PHPCR\NodeInterface; use PHPCR\PathNotFoundException; @@ -656,4 +657,9 @@ public function getDocumentId(object $document): ?string { return $this->unitOfWork->getDocumentId($document); } + + public function isUninitializedObject(mixed $value): bool + { + return $value instanceof Proxy && !$value->__isInitialized(); + } } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Decorator/DocumentManagerDecoratorTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Decorator/DocumentManagerDecoratorTest.php index 5ceafab99..032b41479 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Decorator/DocumentManagerDecoratorTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Decorator/DocumentManagerDecoratorTest.php @@ -19,7 +19,9 @@ public function testCheckIfAllPublicMethodsAreDecorated(): void sort($dmMethods); $dmiMethods = get_class_methods(DocumentManagerInterface::class); - $dmiMethods = array_diff($dmiMethods, ['__construct']); + if (!in_array('isUninitializedObject', $dmiMethods)) { + $dmiMethods[] = 'isUninitializedObject'; // this method will only be added i ORM 4.* + } sort($dmiMethods); $dmdMethods = get_class_methods(OwnDocumentManager::class);