Chris@0: . Chris@0: */ Chris@0: Chris@0: namespace Doctrine\Common\Reflection; Chris@0: Chris@0: use Doctrine\Common\Proxy\Proxy; Chris@0: use ReflectionProperty; Chris@0: Chris@0: /** Chris@0: * PHP Runtime Reflection Public Property - special overrides for public properties. Chris@0: * Chris@0: * @author Marco Pivetta Chris@0: * @since 2.4 Chris@0: */ Chris@0: class RuntimePublicReflectionProperty extends ReflectionProperty Chris@0: { Chris@0: /** Chris@0: * {@inheritDoc} Chris@0: * Chris@0: * Checks is the value actually exist before fetching it. Chris@0: * This is to avoid calling `__get` on the provided $object if it Chris@0: * is a {@see \Doctrine\Common\Proxy\Proxy}. Chris@0: */ Chris@0: public function getValue($object = null) Chris@0: { Chris@0: $name = $this->getName(); Chris@0: Chris@0: if ($object instanceof Proxy && ! $object->__isInitialized()) { Chris@0: $originalInitializer = $object->__getInitializer(); Chris@0: $object->__setInitializer(null); Chris@0: $val = isset($object->$name) ? $object->$name : null; Chris@0: $object->__setInitializer($originalInitializer); Chris@0: Chris@0: return $val; Chris@0: } Chris@0: Chris@0: return isset($object->$name) ? parent::getValue($object) : null; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritDoc} Chris@0: * Chris@0: * Avoids triggering lazy loading via `__set` if the provided object Chris@0: * is a {@see \Doctrine\Common\Proxy\Proxy}. Chris@0: * @link https://bugs.php.net/bug.php?id=63463 Chris@0: */ Chris@0: public function setValue($object, $value = null) Chris@0: { Chris@0: if ( ! ($object instanceof Proxy && ! $object->__isInitialized())) { Chris@0: parent::setValue($object, $value); Chris@0: Chris@0: return; Chris@0: } Chris@0: Chris@0: $originalInitializer = $object->__getInitializer(); Chris@0: $object->__setInitializer(null); Chris@0: parent::setValue($object, $value); Chris@0: $object->__setInitializer($originalInitializer); Chris@0: } Chris@0: }