You are here

private function ProxyGenerator::generateMagicSet 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::generateMagicSet()

Generates the magic setter (currently unused).

Parameters

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

Return value

string

File

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

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 generateMagicSet(ClassMetadata $class) {
  $lazyPublicProperties = $this
    ->getLazyLoadedPublicProperties($class);
  $hasParentSet = $class
    ->getReflectionClass()
    ->hasMethod('__set');
  if (empty($lazyPublicProperties) && !$hasParentSet) {
    return '';
  }
  $inheritDoc = $hasParentSet ? '{@inheritDoc}' : '';
  $magicSet = <<<EOT
    /**
     * {<span class="php-variable">$inheritDoc</span>}
     * @param string \$name
     * @param mixed  \$value
     */
    public function __set(\$name, \$value)
    {

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

            $this->$name = $value;

            return;
        }


EOT;
  }
  if ($hasParentSet) {
    $magicSet .= <<<'EOT'
        $this->__initializer__ && $this->__initializer__->__invoke($this, '__set', array($name, $value));

        return parent::__set($name, $value);
EOT;
  }
  else {
    $magicSet .= "        \$this->\$name = \$value;";
  }
  $magicSet .= "\n    }";
  return $magicSet;
}