You are here

private function ProxyGenerator::generateMagicSet in Plug 7

Generates the magic setter (currently unused).

Parameters

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

Return value

string

File

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

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;
}