mailpoet
/
vendor-prefixed
/
doctrine
/
persistence
/
src
/
Persistence
/
Reflection
/
RuntimeReflectionProperty.php
mailpoet
/
vendor-prefixed
/
doctrine
/
persistence
/
src
/
Persistence
/
Reflection
Last commit date
EnumReflectionProperty.php
9 months ago
RuntimePublicReflectionProperty.php
9 months ago
RuntimeReflectionProperty.php
9 months ago
TypedNoDefaultReflectionProperty.php
9 months ago
TypedNoDefaultReflectionPropertyBase.php
9 months ago
TypedNoDefaultRuntimePublicReflectionProperty.php
9 months ago
index.php
3 years ago
RuntimeReflectionProperty.php
49 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\Persistence\Reflection; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\Common\Proxy\Proxy as CommonProxy; |
| 6 | use MailPoetVendor\Doctrine\Persistence\Proxy; |
| 7 | use ReflectionProperty; |
| 8 | use ReturnTypeWillChange; |
| 9 | use function ltrim; |
| 10 | use function method_exists; |
| 11 | class RuntimeReflectionProperty extends ReflectionProperty |
| 12 | { |
| 13 | private $key; |
| 14 | public function __construct(string $class, string $name) |
| 15 | { |
| 16 | parent::__construct($class, $name); |
| 17 | $this->key = $this->isPrivate() ? "\x00" . ltrim($class, '\\') . "\x00" . $name : ($this->isProtected() ? "\x00*\x00" . $name : $name); |
| 18 | } |
| 19 | #[\ReturnTypeWillChange] |
| 20 | public function getValue($object = null) |
| 21 | { |
| 22 | if ($object === null) { |
| 23 | return parent::getValue($object); |
| 24 | } |
| 25 | return ((array) $object)[$this->key] ?? null; |
| 26 | } |
| 27 | #[\ReturnTypeWillChange] |
| 28 | public function setValue($object, $value = null) |
| 29 | { |
| 30 | if (!($object instanceof Proxy && !$object->__isInitialized())) { |
| 31 | parent::setValue($object, $value); |
| 32 | return; |
| 33 | } |
| 34 | if ($object instanceof CommonProxy) { |
| 35 | $originalInitializer = $object->__getInitializer(); |
| 36 | $object->__setInitializer(null); |
| 37 | parent::setValue($object, $value); |
| 38 | $object->__setInitializer($originalInitializer); |
| 39 | return; |
| 40 | } |
| 41 | if (!method_exists($object, '__setInitialized')) { |
| 42 | return; |
| 43 | } |
| 44 | $object->__setInitialized(\true); |
| 45 | parent::setValue($object, $value); |
| 46 | $object->__setInitialized(\false); |
| 47 | } |
| 48 | } |
| 49 |