Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Metadata/PropertyMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
* fieldName: string,
* normalizer: Normalizer|null,
* extras: array<string, mixed>,
* directAccess: bool,
* }
*/
final class PropertyMetadata
{
public readonly string $propertyName;

private bool $directAccess;

/** @param array<string, mixed> $extras */
public function __construct(
public readonly ReflectionProperty $reflection,
Expand All @@ -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 */
Expand All @@ -49,6 +59,7 @@ public function __serialize(): array
'fieldName' => $this->fieldName,
'normalizer' => $this->normalizer,
'extras' => $this->extras,
'directAccess' => $this->directAccess,
];
}

Expand All @@ -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'];
}
}
Loading