Example #1
0
 /**
  * @param \ReflectionClass                       $originalClass
  * @param \Zend\Code\Generator\PropertyGenerator $prefixInterceptors
  * @param \Zend\Code\Generator\PropertyGenerator $suffixInterceptors
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $prefixInterceptors, PropertyGenerator $suffixInterceptors)
 {
     parent::__construct($originalClass, '__set', array(new ParameterGenerator('name'), new ParameterGenerator('value')));
     $override = $originalClass->hasMethod('__set');
     $this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
     if ($override) {
         $callParent = '$returnValue = & parent::__set($name, $value);';
     } else {
         $callParent = PublicScopeSimulator::getPublicAccessSimulationCode(PublicScopeSimulator::OPERATION_SET, 'name', 'value', null, 'returnValue');
     }
     $this->setBody(InterceptorGenerator::createInterceptedMethodBody($callParent, $this, $prefixInterceptors, $suffixInterceptors));
 }
Example #2
0
 /**
  * @param \Zend\Code\Reflection\MethodReflection $originalMethod
  * @param \Zend\Code\Generator\PropertyGenerator $prefixInterceptors
  * @param \Zend\Code\Generator\PropertyGenerator $suffixInterceptors
  *
  * @return self
  */
 public static function generateMethod(MethodReflection $originalMethod, PropertyGenerator $prefixInterceptors, PropertyGenerator $suffixInterceptors)
 {
     /* @var $method self */
     $method = static::fromReflection($originalMethod);
     $forwardedParams = [];
     foreach ($originalMethod->getParameters() as $parameter) {
         $forwardedParams[] = '$' . $parameter->getName();
     }
     $method->setDocblock('{@inheritDoc}');
     $method->setBody(InterceptorGenerator::createInterceptedMethodBody('$returnValue = parent::' . $originalMethod->getName() . '(' . implode(', ', $forwardedParams) . ');', $method, $prefixInterceptors, $suffixInterceptors));
     return $method;
 }
 /**
  * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util\InterceptorGenerator
  */
 public function testInterceptorGenerator()
 {
     $method = $this->getMock('ProxyManager\\Generator\\MethodGenerator');
     $bar = $this->getMock('ProxyManager\\Generator\\ParameterGenerator');
     $baz = $this->getMock('ProxyManager\\Generator\\ParameterGenerator');
     $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
     $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
     $bar->expects($this->any())->method('getName')->will($this->returnValue('bar'));
     $baz->expects($this->any())->method('getName')->will($this->returnValue('baz'));
     $method->expects($this->any())->method('getName')->will($this->returnValue('fooMethod'));
     $method->expects($this->any())->method('getParameters')->will($this->returnValue(array($bar, $baz)));
     $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
     $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
     $body = InterceptorGenerator::createInterceptedMethodBody('$returnValue = "foo";', $method, $prefixInterceptors, $suffixInterceptors);
     $this->assertSame('if (isset($this->pre[\'fooMethod\'])) {' . "\n" . '    $returnEarly       = false;' . "\n" . '    $prefixReturnValue = $this->pre[\'fooMethod\']->__invoke($this, $this, \'fooMethod\', ' . 'array(\'bar\' => $bar, \'baz\' => $baz), $returnEarly);' . "\n\n" . '    if ($returnEarly) {' . "\n" . '        return $prefixReturnValue;' . "\n" . '    }' . "\n" . '}' . "\n\n" . '$returnValue = "foo";' . "\n\n" . 'if (isset($this->post[\'fooMethod\'])) {' . "\n" . '    $returnEarly       = false;' . "\n" . '    $suffixReturnValue = $this->post[\'fooMethod\']->__invoke($this, $this, \'fooMethod\', ' . 'array(\'bar\' => $bar, \'baz\' => $baz), $returnValue, $returnEarly);' . "\n\n" . '    if ($returnEarly) {' . "\n" . '        return $suffixReturnValue;' . "\n" . '    }' . "\n" . '}' . "\n\n" . 'return $returnValue;', $body);
 }
Example #4
0
 /**
  * Constructor
  *
  * @param ReflectionClass   $originalClass
  * @param PropertyGenerator $prefixInterceptors
  * @param PropertyGenerator $suffixInterceptors
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $prefixInterceptors, PropertyGenerator $suffixInterceptors)
 {
     parent::__construct($originalClass, '__clone');
     $this->setBody(InterceptorGenerator::createInterceptedMethodBody($originalClass->hasMethod('__clone') ? '$returnValue = parent::__clone();' : '$returnValue = null;', $this, $prefixInterceptors, $suffixInterceptors));
 }
Example #5
0
 /**
  * Constructor
  */
 public function __construct(ReflectionClass $originalClass, PropertyGenerator $prefixInterceptors, PropertyGenerator $suffixInterceptors)
 {
     parent::__construct($originalClass, '__sleep');
     $callParent = $originalClass->hasMethod('__sleep') ? '$returnValue = & parent::__sleep();' : '$returnValue = array_keys((array) $this);';
     $this->setBody(InterceptorGenerator::createInterceptedMethodBody($callParent, $this, $prefixInterceptors, $suffixInterceptors));
 }