-
-
Notifications
You must be signed in to change notification settings - Fork 154
-
In my humble opinion, when the entity has the magic __get and/or __set methods and the @property... declaration, the ObjectHelpers::getMagicProperties() should also return them.
/** * @property-read string $createdAt * @property-read string $id */ class PersonEntity { protected array $data = []; public function __construct(array $data) { $uuid = \Ramsey\Uuid\Rfc4122\UuidV7::fromBytes($data['id']); $this->data['id'] = $uuid->toString(); $this->data['createdAt'] = $uuid->getDateTime(); } public function __get(string $name) { if (isset($this->data[$name]) !== true) { throw new InvalidArgumentException(); } return $this->data[$name]; } }
utils/src/Utils/ObjectHelpers.php
Lines 144 to 154 in 17932ce
$uname = ucfirst($name);
$write = $type !== '-read'
&& $rc->hasMethod($nm = 'set' . $uname)
&& ($rm = $rc->getMethod($nm))->name === $nm && !$rm->isPrivate() && !$rm->isStatic();
$read = $type !== '-write'
&& ($rc->hasMethod($nm = 'get' . $uname) || $rc->hasMethod($nm = 'is' . $uname))
&& ($rm = $rc->getMethod($nm))->name === $nm && !$rm->isPrivate() && !$rm->isStatic();
if ($read || $write) {
$props[$name] = $read << 0 | ($nm[0] === 'g') << 1 | $rm->returnsReference() << 2 | $write << 3 | ($type === '-deprecated') << 4;
}
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
This is used purely for the purposes of Nette\SmartObject, which requires the method to be defined.
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment