You are here

private function ProxyGenerator::generateMagicIsset in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/doctrine/common/lib/Doctrine/Common/Proxy/ProxyGenerator.php \Doctrine\Common\Proxy\ProxyGenerator::generateMagicIsset()

Generates the magic issetter invoked when lazy loaded public properties are checked against isset().

Parameters

\Doctrine\Common\Persistence\Mapping\ClassMetadata $class:

Return value

string

File

vendor/doctrine/common/lib/Doctrine/Common/Proxy/ProxyGenerator.php, line 538

Class

ProxyGenerator
This factory is used to generate proxy classes. It builds proxies from given parameters, a template and class metadata.

Namespace

Doctrine\Common\Proxy

Code

private function generateMagicIsset(ClassMetadata $class) {
  $lazyPublicProperties = array_keys($this
    ->getLazyLoadedPublicProperties($class));
  $hasParentIsset = $class
    ->getReflectionClass()
    ->hasMethod('__isset');
  if (empty($lazyPublicProperties) && !$hasParentIsset) {
    return '';
  }
  $inheritDoc = $hasParentIsset ? '{@inheritDoc}' : '';
  $magicIsset = <<<EOT
    /**
     * {<span class="php-variable">$inheritDoc</span>}
     * @param  string \$name
     * @return boolean
     */
    public function __isset(\$name)
    {

EOT;
  if (!empty($lazyPublicProperties)) {
    $magicIsset .= <<<'EOT'
        if (array_key_exists($name, $this->__getLazyProperties())) {
            $this->__initializer__ && $this->__initializer__->__invoke($this, '__isset', array($name));

            return isset($this->$name);
        }


EOT;
  }
  if ($hasParentIsset) {
    $magicIsset .= <<<'EOT'
        $this->__initializer__ && $this->__initializer__->__invoke($this, '__isset', array($name));

        return parent::__isset($name);

EOT;
  }
  else {
    $magicIsset .= "        return false;";
  }
  return $magicIsset . "\n    }";
}