speed up accessing object properties
This commit is contained in:
parent
1aa652e2cb
commit
ef7876e517
@ -82,11 +82,16 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
*/
|
||||
public function getValue($objectOrArray, $propertyPath)
|
||||
{
|
||||
$propertyPath = $this->getPropertyPath($propertyPath);
|
||||
|
||||
$zval = [
|
||||
self::VALUE => $objectOrArray,
|
||||
];
|
||||
|
||||
if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[')) {
|
||||
return $this->readProperty($zval, $propertyPath)[self::VALUE];
|
||||
}
|
||||
|
||||
$propertyPath = $this->getPropertyPath($propertyPath);
|
||||
|
||||
$propertyValues = $this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices);
|
||||
|
||||
return $propertyValues[\count($propertyValues) - 1][self::VALUE];
|
||||
@ -97,6 +102,22 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
*/
|
||||
public function setValue(&$objectOrArray, $propertyPath, $value)
|
||||
{
|
||||
if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[')) {
|
||||
$zval = [
|
||||
self::VALUE => $objectOrArray,
|
||||
];
|
||||
|
||||
try {
|
||||
$this->writeProperty($zval, $propertyPath, $value);
|
||||
|
||||
return;
|
||||
} catch (\TypeError $e) {
|
||||
self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0, $propertyPath);
|
||||
// It wasn't thrown in this class so rethrow it
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
$propertyPath = $this->getPropertyPath($propertyPath);
|
||||
|
||||
$zval = [
|
||||
|
Reference in New Issue
Block a user