88use Doctrine \DBAL \Types \Type ;
99use Doctrine \ORM \EntityManagerInterface ;
1010use Doctrine \ORM \Mapping \ClassMetadata ;
11+ use Doctrine \ORM \Mapping \PropertyAccessors \PropertyAccessor ;
1112use Doctrine \ORM \PersistentCollection ;
1213use Doctrine \ORM \QueryBuilder ;
1314use LogicException ;
14- use ReflectionProperty ;
1515use function array_chunk ;
1616use function array_values ;
1717use function count ;
@@ -123,18 +123,18 @@ private function loadProxies(
123123 int $ maxFetchJoinSameFieldCount ,
124124 ): array
125125 {
126- $ identifierReflection = $ classMetadata ->getSingleIdReflectionProperty (); // e.g. Order::$id reflection
126+ $ identifierAccessor = $ classMetadata ->getSingleIdPropertyAccessor (); // e.g. Order::$id reflection
127127 $ identifierName = $ classMetadata ->getSingleIdentifierFieldName (); // e.g. 'id'
128128
129- if ($ identifierReflection === null ) {
129+ if ($ identifierAccessor === null ) {
130130 throw new LogicException ('Doctrine should use RuntimeReflectionService which never returns null. ' );
131131 }
132132
133133 $ uniqueEntities = [];
134134 $ uninitializedIds = [];
135135
136136 foreach ($ entities as $ entity ) {
137- $ entityId = $ identifierReflection ->getValue ($ entity );
137+ $ entityId = $ identifierAccessor ->getValue ($ entity );
138138 $ entityKey = (string ) $ entityId ;
139139 $ uniqueEntities [$ entityKey ] = $ entity ;
140140
@@ -170,11 +170,11 @@ private function preloadToMany(
170170 int $ maxFetchJoinSameFieldCount ,
171171 ): array
172172 {
173- $ sourceIdentifierReflection = $ sourceClassMetadata ->getSingleIdReflectionProperty (); // e.g. Order::$id reflection
174- $ sourcePropertyReflection = $ sourceClassMetadata ->getReflectionProperty ($ sourcePropertyName ); // e.g. Order::$items reflection
175- $ targetIdentifierReflection = $ targetClassMetadata ->getSingleIdReflectionProperty ();
173+ $ sourceIdentifierAccessor = $ sourceClassMetadata ->getSingleIdPropertyAccessor (); // e.g. Order::$id reflection
174+ $ sourcePropertyAccessor = $ sourceClassMetadata ->getPropertyAccessor ($ sourcePropertyName ); // e.g. Order::$items reflection
175+ $ targetIdentifierAccessor = $ targetClassMetadata ->getSingleIdPropertyAccessor ();
176176
177- if ($ sourceIdentifierReflection === null || $ sourcePropertyReflection === null || $ targetIdentifierReflection === null ) {
177+ if ($ sourceIdentifierAccessor === null || $ sourcePropertyAccessor === null || $ targetIdentifierAccessor === null ) {
178178 throw new LogicException ('Doctrine should use RuntimeReflectionService which never returns null. ' );
179179 }
180180
@@ -184,9 +184,9 @@ private function preloadToMany(
184184 $ uninitializedCollections = [];
185185
186186 foreach ($ sourceEntities as $ sourceEntity ) {
187- $ sourceEntityId = $ sourceIdentifierReflection ->getValue ($ sourceEntity );
187+ $ sourceEntityId = $ sourceIdentifierAccessor ->getValue ($ sourceEntity );
188188 $ sourceEntityKey = (string ) $ sourceEntityId ;
189- $ sourceEntityCollection = $ sourcePropertyReflection ->getValue ($ sourceEntity );
189+ $ sourceEntityCollection = $ sourcePropertyAccessor ->getValue ($ sourceEntity );
190190
191191 if (
192192 $ sourceEntityCollection instanceof PersistentCollection
@@ -199,7 +199,7 @@ private function preloadToMany(
199199 }
200200
201201 foreach ($ sourceEntityCollection as $ targetEntity ) {
202- $ targetEntityKey = (string ) $ targetIdentifierReflection ->getValue ($ targetEntity );
202+ $ targetEntityKey = (string ) $ targetIdentifierAccessor ->getValue ($ targetEntity );
203203 $ targetEntities [$ targetEntityKey ] = $ targetEntity ;
204204 }
205205 }
@@ -216,10 +216,10 @@ private function preloadToMany(
216216 $ targetEntitiesChunk = $ innerLoader (
217217 associationMapping: $ associationMapping ,
218218 sourceClassMetadata: $ sourceClassMetadata ,
219- sourceIdentifierReflection : $ sourceIdentifierReflection ,
219+ sourceIdentifierAccessor : $ sourceIdentifierAccessor ,
220220 sourcePropertyName: $ sourcePropertyName ,
221221 targetClassMetadata: $ targetClassMetadata ,
222- targetIdentifierReflection : $ targetIdentifierReflection ,
222+ targetIdentifierAccessor : $ targetIdentifierAccessor ,
223223 uninitializedSourceEntityIdsChunk: array_values ($ uninitializedSourceEntityIdsChunk ),
224224 uninitializedCollections: $ uninitializedCollections ,
225225 maxFetchJoinSameFieldCount: $ maxFetchJoinSameFieldCount ,
@@ -253,20 +253,20 @@ private function preloadToMany(
253253 private function preloadOneToManyInner (
254254 array |ArrayAccess $ associationMapping ,
255255 ClassMetadata $ sourceClassMetadata ,
256- ReflectionProperty $ sourceIdentifierReflection ,
256+ PropertyAccessor $ sourceIdentifierAccessor ,
257257 string $ sourcePropertyName ,
258258 ClassMetadata $ targetClassMetadata ,
259- ReflectionProperty $ targetIdentifierReflection ,
259+ PropertyAccessor $ targetIdentifierAccessor ,
260260 array $ uninitializedSourceEntityIdsChunk ,
261261 array $ uninitializedCollections ,
262262 int $ maxFetchJoinSameFieldCount ,
263263 ): array
264264 {
265265 $ targetPropertyName = $ sourceClassMetadata ->getAssociationMappedByTargetField ($ sourcePropertyName ); // e.g. 'order'
266- $ targetPropertyReflection = $ targetClassMetadata ->getReflectionProperty ($ targetPropertyName ); // e.g. Item::$order reflection
266+ $ targetPropertyAccessor = $ targetClassMetadata ->getPropertyAccessor ($ targetPropertyName ); // e.g. Item::$order reflection
267267 $ targetEntities = [];
268268
269- if ($ targetPropertyReflection === null ) {
269+ if ($ targetPropertyAccessor === null ) {
270270 throw new LogicException ('Doctrine should use RuntimeReflectionService which never returns null. ' );
271271 }
272272
@@ -280,11 +280,11 @@ private function preloadOneToManyInner(
280280 );
281281
282282 foreach ($ targetEntitiesList as $ targetEntity ) {
283- $ sourceEntity = $ targetPropertyReflection ->getValue ($ targetEntity );
284- $ sourceEntityKey = (string ) $ sourceIdentifierReflection ->getValue ($ sourceEntity );
283+ $ sourceEntity = $ targetPropertyAccessor ->getValue ($ targetEntity );
284+ $ sourceEntityKey = (string ) $ sourceIdentifierAccessor ->getValue ($ sourceEntity );
285285 $ uninitializedCollections [$ sourceEntityKey ]->add ($ targetEntity );
286286
287- $ targetEntityKey = (string ) $ targetIdentifierReflection ->getValue ($ targetEntity );
287+ $ targetEntityKey = (string ) $ targetIdentifierAccessor ->getValue ($ targetEntity );
288288 $ targetEntities [$ targetEntityKey ] = $ targetEntity ;
289289 }
290290
@@ -306,10 +306,10 @@ private function preloadOneToManyInner(
306306 private function preloadManyToManyInner (
307307 array |ArrayAccess $ associationMapping ,
308308 ClassMetadata $ sourceClassMetadata ,
309- ReflectionProperty $ sourceIdentifierReflection ,
309+ PropertyAccessor $ sourceIdentifierAccessor ,
310310 string $ sourcePropertyName ,
311311 ClassMetadata $ targetClassMetadata ,
312- ReflectionProperty $ targetIdentifierReflection ,
312+ PropertyAccessor $ targetIdentifierAccessor ,
313313 array $ uninitializedSourceEntityIdsChunk ,
314314 array $ uninitializedCollections ,
315315 int $ maxFetchJoinSameFieldCount ,
@@ -356,7 +356,7 @@ private function preloadManyToManyInner(
356356 }
357357
358358 foreach ($ this ->loadEntitiesBy ($ targetClassMetadata , $ targetIdentifierName , $ sourceClassMetadata , array_values ($ uninitializedTargetEntityIds ), $ maxFetchJoinSameFieldCount ) as $ targetEntity ) {
359- $ targetEntityKey = (string ) $ targetIdentifierReflection ->getValue ($ targetEntity );
359+ $ targetEntityKey = (string ) $ targetIdentifierAccessor ->getValue ($ targetEntity );
360360 $ targetEntities [$ targetEntityKey ] = $ targetEntity ;
361361 }
362362
@@ -389,17 +389,17 @@ private function preloadToOne(
389389 int $ maxFetchJoinSameFieldCount ,
390390 ): array
391391 {
392- $ sourcePropertyReflection = $ sourceClassMetadata ->getReflectionProperty ($ sourcePropertyName ); // e.g. Item::$order reflection
392+ $ sourcePropertyAccessor = $ sourceClassMetadata ->getPropertyAccessor ($ sourcePropertyName ); // e.g. Item::$order reflection
393393
394- if ($ sourcePropertyReflection === null ) {
394+ if ($ sourcePropertyAccessor === null ) {
395395 throw new LogicException ('Doctrine should use RuntimeReflectionService which never returns null. ' );
396396 }
397397
398398 $ batchSize ??= self ::PRELOAD_ENTITY_DEFAULT_BATCH_SIZE ;
399399 $ targetEntities = [];
400400
401401 foreach ($ sourceEntities as $ sourceEntity ) {
402- $ targetEntity = $ sourcePropertyReflection ->getValue ($ sourceEntity );
402+ $ targetEntity = $ sourcePropertyAccessor ->getValue ($ sourceEntity );
403403
404404 if ($ targetEntity === null ) {
405405 continue ;
0 commit comments