55use ArrayAccess ;
66use Doctrine \ORM \EntityManagerInterface ;
77use Doctrine \ORM \Mapping \ClassMetadata ;
8+ use Doctrine \ORM \Mapping \PropertyAccessors \PropertyAccessor ;
89use Doctrine \ORM \PersistentCollection ;
910use Doctrine \ORM \QueryBuilder ;
1011use LogicException ;
11- use ReflectionProperty ;
1212use function array_chunk ;
1313use function array_values ;
1414use function count ;
@@ -120,18 +120,18 @@ private function loadProxies(
120120 int $ maxFetchJoinSameFieldCount ,
121121 ): array
122122 {
123- $ identifierReflection = $ classMetadata ->getSingleIdReflectionProperty (); // e.g. Order::$id reflection
123+ $ identifierAccessor = $ classMetadata ->getSingleIdPropertyAccessor (); // e.g. Order::$id reflection
124124 $ identifierName = $ classMetadata ->getSingleIdentifierFieldName (); // e.g. 'id'
125125
126- if ($ identifierReflection === null ) {
126+ if ($ identifierAccessor === null ) {
127127 throw new LogicException ('Doctrine should use RuntimeReflectionService which never returns null. ' );
128128 }
129129
130130 $ uniqueEntities = [];
131131 $ uninitializedIds = [];
132132
133133 foreach ($ entities as $ entity ) {
134- $ entityId = $ identifierReflection ->getValue ($ entity );
134+ $ entityId = $ identifierAccessor ->getValue ($ entity );
135135 $ entityKey = (string ) $ entityId ;
136136 $ uniqueEntities [$ entityKey ] = $ entity ;
137137
@@ -167,11 +167,11 @@ private function preloadToMany(
167167 int $ maxFetchJoinSameFieldCount ,
168168 ): array
169169 {
170- $ sourceIdentifierReflection = $ sourceClassMetadata ->getSingleIdReflectionProperty (); // e.g. Order::$id reflection
171- $ sourcePropertyReflection = $ sourceClassMetadata ->getReflectionProperty ($ sourcePropertyName ); // e.g. Order::$items reflection
172- $ targetIdentifierReflection = $ targetClassMetadata ->getSingleIdReflectionProperty ();
170+ $ sourceIdentifierAccessor = $ sourceClassMetadata ->getSingleIdPropertyAccessor (); // e.g. Order::$id reflection
171+ $ sourcePropertyAccessor = $ sourceClassMetadata ->getPropertyAccessor ($ sourcePropertyName ); // e.g. Order::$items reflection
172+ $ targetIdentifierAccessor = $ targetClassMetadata ->getSingleIdPropertyAccessor ();
173173
174- if ($ sourceIdentifierReflection === null || $ sourcePropertyReflection === null || $ targetIdentifierReflection === null ) {
174+ if ($ sourceIdentifierAccessor === null || $ sourcePropertyAccessor === null || $ targetIdentifierAccessor === null ) {
175175 throw new LogicException ('Doctrine should use RuntimeReflectionService which never returns null. ' );
176176 }
177177
@@ -181,9 +181,9 @@ private function preloadToMany(
181181 $ uninitializedCollections = [];
182182
183183 foreach ($ sourceEntities as $ sourceEntity ) {
184- $ sourceEntityId = $ sourceIdentifierReflection ->getValue ($ sourceEntity );
184+ $ sourceEntityId = $ sourceIdentifierAccessor ->getValue ($ sourceEntity );
185185 $ sourceEntityKey = (string ) $ sourceEntityId ;
186- $ sourceEntityCollection = $ sourcePropertyReflection ->getValue ($ sourceEntity );
186+ $ sourceEntityCollection = $ sourcePropertyAccessor ->getValue ($ sourceEntity );
187187
188188 if (
189189 $ sourceEntityCollection instanceof PersistentCollection
@@ -196,7 +196,7 @@ private function preloadToMany(
196196 }
197197
198198 foreach ($ sourceEntityCollection as $ targetEntity ) {
199- $ targetEntityKey = (string ) $ targetIdentifierReflection ->getValue ($ targetEntity );
199+ $ targetEntityKey = (string ) $ targetIdentifierAccessor ->getValue ($ targetEntity );
200200 $ targetEntities [$ targetEntityKey ] = $ targetEntity ;
201201 }
202202 }
@@ -213,10 +213,10 @@ private function preloadToMany(
213213 $ targetEntitiesChunk = $ innerLoader (
214214 associationMapping: $ associationMapping ,
215215 sourceClassMetadata: $ sourceClassMetadata ,
216- sourceIdentifierReflection : $ sourceIdentifierReflection ,
216+ sourceIdentifierAccessor : $ sourceIdentifierAccessor ,
217217 sourcePropertyName: $ sourcePropertyName ,
218218 targetClassMetadata: $ targetClassMetadata ,
219- targetIdentifierReflection : $ targetIdentifierReflection ,
219+ targetIdentifierAccessor : $ targetIdentifierAccessor ,
220220 uninitializedSourceEntityIdsChunk: array_values ($ uninitializedSourceEntityIdsChunk ),
221221 uninitializedCollections: $ uninitializedCollections ,
222222 maxFetchJoinSameFieldCount: $ maxFetchJoinSameFieldCount ,
@@ -250,20 +250,20 @@ private function preloadToMany(
250250 private function preloadOneToManyInner (
251251 array |ArrayAccess $ associationMapping ,
252252 ClassMetadata $ sourceClassMetadata ,
253- ReflectionProperty $ sourceIdentifierReflection ,
253+ PropertyAccessor $ sourceIdentifierAccessor ,
254254 string $ sourcePropertyName ,
255255 ClassMetadata $ targetClassMetadata ,
256- ReflectionProperty $ targetIdentifierReflection ,
256+ PropertyAccessor $ targetIdentifierAccessor ,
257257 array $ uninitializedSourceEntityIdsChunk ,
258258 array $ uninitializedCollections ,
259259 int $ maxFetchJoinSameFieldCount ,
260260 ): array
261261 {
262262 $ targetPropertyName = $ sourceClassMetadata ->getAssociationMappedByTargetField ($ sourcePropertyName ); // e.g. 'order'
263- $ targetPropertyReflection = $ targetClassMetadata ->getReflectionProperty ($ targetPropertyName ); // e.g. Item::$order reflection
263+ $ targetPropertyAccessor = $ targetClassMetadata ->getPropertyAccessor ($ targetPropertyName ); // e.g. Item::$order reflection
264264 $ targetEntities = [];
265265
266- if ($ targetPropertyReflection === null ) {
266+ if ($ targetPropertyAccessor === null ) {
267267 throw new LogicException ('Doctrine should use RuntimeReflectionService which never returns null. ' );
268268 }
269269
@@ -276,11 +276,11 @@ private function preloadOneToManyInner(
276276 );
277277
278278 foreach ($ targetEntitiesList as $ targetEntity ) {
279- $ sourceEntity = $ targetPropertyReflection ->getValue ($ targetEntity );
280- $ sourceEntityKey = (string ) $ sourceIdentifierReflection ->getValue ($ sourceEntity );
279+ $ sourceEntity = $ targetPropertyAccessor ->getValue ($ targetEntity );
280+ $ sourceEntityKey = (string ) $ sourceIdentifierAccessor ->getValue ($ sourceEntity );
281281 $ uninitializedCollections [$ sourceEntityKey ]->add ($ targetEntity );
282282
283- $ targetEntityKey = (string ) $ targetIdentifierReflection ->getValue ($ targetEntity );
283+ $ targetEntityKey = (string ) $ targetIdentifierAccessor ->getValue ($ targetEntity );
284284 $ targetEntities [$ targetEntityKey ] = $ targetEntity ;
285285 }
286286
@@ -302,10 +302,10 @@ private function preloadOneToManyInner(
302302 private function preloadManyToManyInner (
303303 array |ArrayAccess $ associationMapping ,
304304 ClassMetadata $ sourceClassMetadata ,
305- ReflectionProperty $ sourceIdentifierReflection ,
305+ PropertyAccessor $ sourceIdentifierAccessor ,
306306 string $ sourcePropertyName ,
307307 ClassMetadata $ targetClassMetadata ,
308- ReflectionProperty $ targetIdentifierReflection ,
308+ PropertyAccessor $ targetIdentifierAccessor ,
309309 array $ uninitializedSourceEntityIdsChunk ,
310310 array $ uninitializedCollections ,
311311 int $ maxFetchJoinSameFieldCount ,
@@ -346,7 +346,7 @@ private function preloadManyToManyInner(
346346 }
347347
348348 foreach ($ this ->loadEntitiesBy ($ targetClassMetadata , $ targetIdentifierName , array_values ($ uninitializedTargetEntityIds ), $ maxFetchJoinSameFieldCount ) as $ targetEntity ) {
349- $ targetEntityKey = (string ) $ targetIdentifierReflection ->getValue ($ targetEntity );
349+ $ targetEntityKey = (string ) $ targetIdentifierAccessor ->getValue ($ targetEntity );
350350 $ targetEntities [$ targetEntityKey ] = $ targetEntity ;
351351 }
352352
@@ -379,17 +379,17 @@ private function preloadToOne(
379379 int $ maxFetchJoinSameFieldCount ,
380380 ): array
381381 {
382- $ sourcePropertyReflection = $ sourceClassMetadata ->getReflectionProperty ($ sourcePropertyName ); // e.g. Item::$order reflection
382+ $ sourcePropertyAccessor = $ sourceClassMetadata ->getPropertyAccessor ($ sourcePropertyName ); // e.g. Item::$order reflection
383383
384- if ($ sourcePropertyReflection === null ) {
384+ if ($ sourcePropertyAccessor === null ) {
385385 throw new LogicException ('Doctrine should use RuntimeReflectionService which never returns null. ' );
386386 }
387387
388388 $ batchSize ??= self ::PRELOAD_ENTITY_DEFAULT_BATCH_SIZE ;
389389 $ targetEntities = [];
390390
391391 foreach ($ sourceEntities as $ sourceEntity ) {
392- $ targetEntity = $ sourcePropertyReflection ->getValue ($ sourceEntity );
392+ $ targetEntity = $ sourcePropertyAccessor ->getValue ($ sourceEntity );
393393
394394 if ($ targetEntity === null ) {
395395 continue ;
0 commit comments