Skip to content

Commit 4402ba5

Browse files
authored
Address deprecation of the ORM's ClassMetadata::$reflFields property
1 parent 211b6fe commit 4402ba5

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

src/Tree/Strategy/ORM/Closure.php

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\ORM\EntityManagerInterface;
1515
use Doctrine\ORM\Mapping\AssociationMapping;
1616
use Doctrine\ORM\Mapping\ClassMetadata as ORMClassMetadata;
17+
use Doctrine\ORM\Mapping\PropertyAccessors\PropertyAccessorFactory;
1718
use Doctrine\ORM\Mapping\ToOneOwningSideMapping;
1819
use Doctrine\ORM\Query;
1920
use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory;
@@ -132,10 +133,21 @@ public function processMetadataLoad($em, $meta)
132133
'fetch' => ORMClassMetadata::FETCH_LAZY,
133134
];
134135
$closureMetadata->mapManyToOne($ancestorMapping);
135-
$closureMetadata->reflFields['ancestor'] = $cmf
136-
->getReflectionService()
137-
->getAccessibleProperty($closureMetadata->getName(), 'ancestor')
138-
;
136+
137+
if (property_exists($closureMetadata, 'propertyAccessors')) {
138+
// ORM 3.4+
139+
/** @phpstan-ignore-next-line class.NotFound Class introduced in ORM 3.4 */
140+
$closureMetadata->propertyAccessors['ancestor'] = PropertyAccessorFactory::createPropertyAccessor(
141+
$closureMetadata->getName(),
142+
'ancestor'
143+
);
144+
} else {
145+
// ORM 3.3-
146+
$closureMetadata->reflFields['ancestor'] = $cmf
147+
->getReflectionService()
148+
->getAccessibleProperty($closureMetadata->getName(), 'ancestor')
149+
;
150+
}
139151
}
140152

141153
if (!$closureMetadata->hasAssociation('descendant')) {
@@ -170,10 +182,21 @@ public function processMetadataLoad($em, $meta)
170182
'fetch' => ORMClassMetadata::FETCH_LAZY,
171183
];
172184
$closureMetadata->mapManyToOne($descendantMapping);
173-
$closureMetadata->reflFields['descendant'] = $cmf
174-
->getReflectionService()
175-
->getAccessibleProperty($closureMetadata->getName(), 'descendant')
176-
;
185+
186+
if (property_exists($closureMetadata, 'propertyAccessors')) {
187+
// ORM 3.4+
188+
/** @phpstan-ignore-next-line class.NotFound Class introduced in ORM 3.4 */
189+
$closureMetadata->propertyAccessors['descendant'] = PropertyAccessorFactory::createPropertyAccessor(
190+
$closureMetadata->getName(),
191+
'descendant'
192+
);
193+
} else {
194+
// ORM 3.3-
195+
$closureMetadata->reflFields['descendant'] = $cmf
196+
->getReflectionService()
197+
->getAccessibleProperty($closureMetadata->getName(), 'descendant')
198+
;
199+
}
177200
}
178201

179202
if (!$this->hasClosureTableUniqueConstraint($closureMetadata)) {

src/Tree/Strategy/ORM/Nested.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,17 @@ public function shiftRL(EntityManagerInterface $em, $class, $first, $delta, $roo
626626

627627
$nodeMeta = $em->getClassMetadata(get_class($node));
628628

629-
if (!array_key_exists($config['left'], $nodeMeta->getReflectionProperties())) {
630-
continue;
629+
if (property_exists($nodeMeta, 'propertyAccessors')) {
630+
// ORM 3.4+
631+
/** @phpstan-ignore-next-line method.NotFound Method introduced in ORM 3.4 */
632+
if (!array_key_exists($config['left'], $nodeMeta->getPropertyAccessors())) {
633+
continue;
634+
}
635+
} else {
636+
// ORM 3.3-
637+
if (!array_key_exists($config['left'], $nodeMeta->getReflectionProperties())) {
638+
continue;
639+
}
631640
}
632641

633642
$oid = spl_object_id($node);
@@ -717,8 +726,17 @@ public function shiftRangeRL(EntityManagerInterface $em, $class, $first, $last,
717726

718727
$nodeMeta = $em->getClassMetadata(get_class($node));
719728

720-
if (!array_key_exists($config['left'], $nodeMeta->getReflectionProperties())) {
721-
continue;
729+
if (property_exists($nodeMeta, 'propertyAccessors')) {
730+
// ORM 3.4+
731+
/** @phpstan-ignore-next-line method.NotFound Method introduced in ORM 3.4 */
732+
if (!array_key_exists($config['left'], $nodeMeta->getPropertyAccessors())) {
733+
continue;
734+
}
735+
} else {
736+
// ORM 3.3-
737+
if (!array_key_exists($config['left'], $nodeMeta->getReflectionProperties())) {
738+
continue;
739+
}
722740
}
723741

724742
$left = $meta->getReflectionProperty($config['left'])->getValue($node);

0 commit comments

Comments
 (0)