From 1b349f05e6945517a7615b12bf086fee03c622ee Mon Sep 17 00:00:00 2001 From: David Badura Date: Thu, 26 Feb 2026 13:08:47 +0100 Subject: [PATCH] property metadata direct access --- src/Metadata/PropertyMetadata.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Metadata/PropertyMetadata.php b/src/Metadata/PropertyMetadata.php index 2e75dfa7..2482966e 100644 --- a/src/Metadata/PropertyMetadata.php +++ b/src/Metadata/PropertyMetadata.php @@ -14,12 +14,15 @@ * fieldName: string, * normalizer: Normalizer|null, * extras: array, + * directAccess: bool, * } */ final class PropertyMetadata { public readonly string $propertyName; + private bool $directAccess; + /** @param array $extras */ public function __construct( public readonly ReflectionProperty $reflection, @@ -28,16 +31,23 @@ public function __construct( public array $extras = [], ) { $this->propertyName = $reflection->getName(); + $this->directAccess = $reflection->isPublic(); } public function setValue(object $object, mixed $value): void { + if ($this->directAccess) { + $object->{$this->propertyName} = $value; + + return; + } + $this->reflection->setValue($object, $value); } public function getValue(object $object): mixed { - return $this->reflection->getValue($object); + return $this->directAccess ? $object->{$this->propertyName} : $this->reflection->getValue($object); } /** @return serialized */ @@ -49,6 +59,7 @@ public function __serialize(): array 'fieldName' => $this->fieldName, 'normalizer' => $this->normalizer, 'extras' => $this->extras, + 'directAccess' => $this->directAccess, ]; } @@ -60,5 +71,6 @@ public function __unserialize(array $data): void $this->fieldName = $data['fieldName']; $this->normalizer = $data['normalizer']; $this->extras = $data['extras']; + $this->directAccess = $data['directAccess']; } }