* @license MIT */ class MagicUnset extends MagicMethodGenerator { /** * Constructor */ public function __construct( ReflectionClass $originalClass, PropertyGenerator $valueHolder, PropertyGenerator $prefixInterceptors, PropertyGenerator $suffixInterceptors, PublicPropertiesMap $publicProperties ) { parent::__construct($originalClass, '__unset', array(new ParameterGenerator('name'))); $override = $originalClass->hasMethod('__unset'); $valueHolderName = $valueHolder->getName(); $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name'); $callParent = PublicScopeSimulator::getPublicAccessSimulationCode( PublicScopeSimulator::OPERATION_UNSET, 'name', 'value', $valueHolder, 'returnValue' ); if (! $publicProperties->isEmpty()) { $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" . ' unset($this->' . $valueHolderName . '->$name);' . "\n} else {\n $callParent\n}\n\n"; } $callParent .= '$returnValue = false;'; $this->setBody( InterceptorGenerator::createInterceptedMethodBody( $callParent, $this, $valueHolder, $prefixInterceptors, $suffixInterceptors ) ); } }