Skip to content

Commit d60a85b

Browse files
Merge branch '5.4' into 6.4
* 5.4: synchronize IBAN formats [PropertyAccess] Fix handling property names with a `.`
2 parents e4d9b00 + 2d75186 commit d60a85b

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

PropertyAccessor.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function getValue(object|array $objectOrArray, string|PropertyPathInterfa
9595
self::VALUE => $objectOrArray,
9696
];
9797

98-
if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[?')) {
98+
if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[?') || $objectOrArray instanceof \stdClass && property_exists($objectOrArray, $propertyPath))) {
9999
return $this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty)[self::VALUE];
100100
}
101101

@@ -111,7 +111,7 @@ public function getValue(object|array $objectOrArray, string|PropertyPathInterfa
111111
*/
112112
public function setValue(object|array &$objectOrArray, string|PropertyPathInterface $propertyPath, mixed $value)
113113
{
114-
if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[')) {
114+
if (\is_object($objectOrArray) && (false === strpbrk((string) $propertyPath, '.[') || $objectOrArray instanceof \stdClass && property_exists($objectOrArray, $propertyPath))) {
115115
$zval = [
116116
self::VALUE => $objectOrArray,
117117
];
@@ -214,7 +214,13 @@ public function isReadable(object|array $objectOrArray, string|PropertyPathInter
214214
$zval = [
215215
self::VALUE => $objectOrArray,
216216
];
217-
$this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices);
217+
218+
// handle stdClass with properties with a dot in the name
219+
if ($objectOrArray instanceof \stdClass && str_contains($propertyPath, '.') && property_exists($objectOrArray, $propertyPath)) {
220+
$this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty);
221+
} else {
222+
$this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices);
223+
}
218224

219225
return true;
220226
} catch (AccessException) {
@@ -232,6 +238,14 @@ public function isWritable(object|array $objectOrArray, string|PropertyPathInter
232238
$zval = [
233239
self::VALUE => $objectOrArray,
234240
];
241+
242+
// handle stdClass with properties with a dot in the name
243+
if ($objectOrArray instanceof \stdClass && str_contains($propertyPath, '.') && property_exists($objectOrArray, $propertyPath)) {
244+
$this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty);
245+
246+
return true;
247+
}
248+
235249
$propertyValues = $this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength() - 1);
236250

237251
for ($i = \count($propertyValues) - 1; 0 <= $i; --$i) {

Tests/PropertyAccessorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ public static function getValidWritePropertyPaths()
526526
[['firstName' => 'Bernhard'], '[firstName]', 'Bernhard'],
527527
[['index' => ['firstName' => 'Bernhard']], '[index][firstName]', 'Bernhard'],
528528
[(object) ['firstName' => 'Bernhard'], 'firstName', 'Bernhard'],
529+
[(object) ['first.Name' => 'Bernhard'], 'first.Name', 'Bernhard'],
529530
[(object) ['property' => ['firstName' => 'Bernhard']], 'property[firstName]', 'Bernhard'],
530531
[['index' => (object) ['firstName' => 'Bernhard']], '[index].firstName', 'Bernhard'],
531532
[(object) ['property' => (object) ['firstName' => 'Bernhard']], 'property.firstName', 'Bernhard'],

0 commit comments

Comments
 (0)