You are here

class RuntimePublicReflectionProperty in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/doctrine/common/lib/Doctrine/Common/Reflection/RuntimePublicReflectionProperty.php \Doctrine\Common\Reflection\RuntimePublicReflectionProperty

PHP Runtime Reflection Public Property - special overrides for public properties.

@author Marco Pivetta <ocramius@gmail.com> @since 2.4

Hierarchy

Expanded class hierarchy of RuntimePublicReflectionProperty

2 files declare their use of RuntimePublicReflectionProperty
RuntimePublicReflectionPropertyTest.php in vendor/doctrine/common/tests/Doctrine/Tests/Common/Reflection/RuntimePublicReflectionPropertyTest.php
RuntimeReflectionService.php in vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php

File

vendor/doctrine/common/lib/Doctrine/Common/Reflection/RuntimePublicReflectionProperty.php, line 31

Namespace

Doctrine\Common\Reflection
View source
class RuntimePublicReflectionProperty extends ReflectionProperty {

  /**
   * {@inheritDoc}
   *
   * Checks is the value actually exist before fetching it.
   * This is to avoid calling `__get` on the provided $object if it
   * is a {@see \Doctrine\Common\Proxy\Proxy}.
   */
  public function getValue($object = null) {
    $name = $this
      ->getName();
    if ($object instanceof Proxy && !$object
      ->__isInitialized()) {
      $originalInitializer = $object
        ->__getInitializer();
      $object
        ->__setInitializer(null);
      $val = isset($object->{$name}) ? $object->{$name} : null;
      $object
        ->__setInitializer($originalInitializer);
      return $val;
    }
    return isset($object->{$name}) ? parent::getValue($object) : null;
  }

  /**
   * {@inheritDoc}
   *
   * Avoids triggering lazy loading via `__set` if the provided object
   * is a {@see \Doctrine\Common\Proxy\Proxy}.
   * @link https://bugs.php.net/bug.php?id=63463
   */
  public function setValue($object, $value = null) {
    if (!($object instanceof Proxy && !$object
      ->__isInitialized())) {
      parent::setValue($object, $value);
      return;
    }
    $originalInitializer = $object
      ->__getInitializer();
    $object
      ->__setInitializer(null);
    parent::setValue($object, $value);
    $object
      ->__setInitializer($originalInitializer);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RuntimePublicReflectionProperty::getValue public function Checks is the value actually exist before fetching it. This is to avoid calling `__get` on the provided $object if it is a {
RuntimePublicReflectionProperty::setValue public function Avoids triggering lazy loading via `__set` if the provided object is a {@link https://bugs.php.net/bug.php?id=63463