File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,6 +8,11 @@ awareness about deprecated code.
88
99# Upgrade to 4.0
1010
11+ ## BC Break: Added ` ObjectManager::isUninitializedObject() `
12+
13+ Classes implementing ` Doctrine\Persistence\ObjectManager ` must implement this
14+ new method.
15+
1116## BC Break: Added type declarations
1217
1318The code base is now fully typed, meaning properties, parameters and return
Original file line number Diff line number Diff line change @@ -5,11 +5,6 @@ parameters:
55 count : 1
66 path : src/Persistence/Mapping/Driver/StaticPHPDriver.php
77
8- -
9- message : " #^Call to function method_exists\\ (\\ ) with TObjectManager of Doctrine\\\\ Persistence\\\\ ObjectManager and 'isUninitializedObje…' will always evaluate to true\\ .$#"
10- count : 1
11- path : src/Persistence/ObjectManagerDecorator.php
12-
138 -
149 message : " #^Doctrine\\\\ Persistence\\\\ Reflection\\\\ EnumReflectionProperty\\ :\\ :__construct\\ (\\ ) does not call parent constructor from ReflectionProperty\\ .$#"
1510 count : 1
Original file line number Diff line number Diff line change 77use Doctrine \Persistence \Mapping \ClassMetadata ;
88use Doctrine \Persistence \Mapping \ClassMetadataFactory ;
99
10- /**
11- * Contract for a Doctrine persistence layer ObjectManager class to implement.
12- *
13- * @method bool isUninitializedObject(mixed $value) Implementing this method will be mandatory in version 4.
14- */
10+ /** Contract for a Doctrine persistence layer ObjectManager class to implement. */
1511interface ObjectManager
1612{
1713 /**
@@ -122,6 +118,9 @@ public function getMetadataFactory(): ClassMetadataFactory;
122118 */
123119 public function initializeObject (object $ obj ): void ;
124120
121+ /** Helper method to check whether a lazy loading proxy or persistent collection has been initialized. */
122+ public function isUninitializedObject (mixed $ value ): bool ;
123+
125124 /**
126125 * Checks if the object is part of the current UnitOfWork and therefore managed.
127126 */
Original file line number Diff line number Diff line change 44
55namespace Doctrine \Persistence ;
66
7- use BadMethodCallException ;
87use Doctrine \Persistence \Mapping \ClassMetadata ;
98use Doctrine \Persistence \Mapping \ClassMetadataFactory ;
109
11- use function get_class ;
12- use function method_exists ;
13- use function sprintf ;
14-
1510/**
1611 * Base class to simplify ObjectManager decorators
1712 *
@@ -83,23 +78,6 @@ public function initializeObject(object $obj): void
8378
8479 public function isUninitializedObject (mixed $ value ): bool
8580 {
86- if (! method_exists ($ this ->wrapped , 'isUninitializedObject ' )) {
87- $ wrappedClass = get_class ($ this ->wrapped );
88-
89- throw new BadMethodCallException (sprintf (
90- <<<'EXCEPTION'
91- Context: Trying to call %s
92- Problem: The wrapped ObjectManager, an instance of %s does not implement this method.
93- Solution: Implement %s::isUninitializedObject() with a signature compatible with this one:
94- public function isUninitializedObject(mixed $value): bool
95- EXCEPTION
96- ,
97- __METHOD__ ,
98- $ wrappedClass ,
99- $ wrappedClass ,
100- ));
101- }
102-
10381 return $ this ->wrapped ->isUninitializedObject ($ value );
10482 }
10583
Original file line number Diff line number Diff line change 44
55namespace Doctrine \Tests \Persistence ;
66
7- use BadMethodCallException ;
87use Doctrine \Persistence \Mapping \ClassMetadata ;
98use Doctrine \Persistence \Mapping \ClassMetadataFactory ;
109use Doctrine \Persistence \ObjectManager ;
@@ -159,32 +158,15 @@ public function testIsUninitializedObject(): void
159158 {
160159 $ object = new TestObject ();
161160
162- $ wrapped = $ this ->createMock (ObjectManagerV4::class);
163- $ decorated = new NullObjectManagerDecorator ($ wrapped );
164- $ wrapped ->expects (self ::once ())
161+ $ this ->wrapped ->expects (self ::once ())
165162 ->method ('isUninitializedObject ' )
166163 ->with ($ object )
167164 ->willReturn (false );
168165
169- self ::assertFalse ($ decorated ->isUninitializedObject ($ object ));
170- }
171-
172- public function testIsThrowsWhenTheWrappedObjectManagerDoesNotImplementObjectManagerV4 (): void
173- {
174- $ object = new TestObject ();
175-
176- $ this ->expectException (BadMethodCallException::class);
177- $ decorated = new NullObjectManagerDecorator ($ this ->createMock (ObjectManager::class));
178-
179- self ::assertFalse ($ decorated ->isUninitializedObject ($ object ));
166+ self ::assertFalse ($ this ->decorated ->isUninitializedObject ($ object ));
180167 }
181168}
182169
183- interface ObjectManagerV4 extends ObjectManager
184- {
185- public function isUninitializedObject (mixed $ object ): bool ;
186- }
187-
188170/** @extends ObjectManagerDecorator<ObjectManager&MockObject> */
189171class NullObjectManagerDecorator extends ObjectManagerDecorator
190172{
You can’t perform that action at this time.
0 commit comments