private function generateMagicSet(ClassMetadata $class)
{
$lazyPublicProperties = $this->getLazyLoadedPublicProperties($class);
$hasParentSet = $class->getReflectionClass()->hasMethod('__set');
if (empty($lazyPublicProperties) && !$hasParentSet) {
return '';
}
$inheritDoc = $hasParentSet ? '{@inheritDoc}' : '';
$magicSet = <<<EOT
/**
* {$inheritDoc}
* @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', [$name, $value]);
$this->$name = $value;
return;
}
EOT;
}
if ($hasParentSet) {
$magicSet .= <<<'EOT'
$this->__initializer__ && $this->__initializer__->__invoke($this, '__set', [$name, $value]);
return parent::__set($name, $value);
EOT;
} else {
$magicSet .= " \$this->\$name = \$value;";
}
$magicSet .= "\n }";
return $magicSet;
}