public function testBodyStructure()
 {
     $prefixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
     $suffixInterceptors = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
     $prefixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('pre'));
     $suffixInterceptors->expects($this->any())->method('getName')->will($this->returnValue('post'));
     $method = InterceptedMethod::generateMethod(new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicByReferenceParameterMethod'), $prefixInterceptors, $suffixInterceptors);
     $this->assertInstanceOf('ProxyManager\\Generator\\MethodGenerator', $method);
     $this->assertSame('publicByReferenceParameterMethod', $method->getName());
     $this->assertCount(2, $method->getParameters());
     $this->assertGreaterThan(0, strpos($method->getBody(), '$returnValue = parent::publicByReferenceParameterMethod($param, $byRefParam);'));
 }
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     CanProxyAssertion::assertClassCanBeProxied($originalClass, false);
     $classGenerator->setExtendedClass($originalClass->getName());
     $classGenerator->setImplementedInterfaces(array('ProxyManager\\Proxy\\AccessInterceptorInterface'));
     $classGenerator->addPropertyFromGenerator($prefixInterceptors = new MethodPrefixInterceptors());
     $classGenerator->addPropertyFromGenerator($suffixInterceptors = new MethodPrefixInterceptors());
     array_map(function (MethodGenerator $generatedMethod) use($originalClass, $classGenerator) {
         ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
     }, array_merge(array_map(function (ReflectionMethod $method) use($prefixInterceptors, $suffixInterceptors) {
         return InterceptedMethod::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), $prefixInterceptors, $suffixInterceptors);
     }, ProxiedMethodsFilter::getProxiedMethods($originalClass, array('__get', '__set', '__isset', '__unset', '__clone', '__sleep'))), array(new Constructor($originalClass, $prefixInterceptors, $suffixInterceptors), new SetMethodPrefixInterceptor($prefixInterceptors), new SetMethodSuffixInterceptor($suffixInterceptors), new MagicGet($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicSet($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicIsset($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicUnset($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicSleep($originalClass, $prefixInterceptors, $suffixInterceptors), new MagicClone($originalClass, $prefixInterceptors, $suffixInterceptors))));
 }
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     if ($originalClass->isInterface()) {
         throw InvalidProxiedClassException::interfaceNotSupported($originalClass);
     }
     $classGenerator->setExtendedClass($originalClass->getName());
     $classGenerator->setImplementedInterfaces(array('ProxyManager\\Proxy\\AccessInterceptorInterface'));
     $classGenerator->addPropertyFromGenerator($prefixInterceptors = new MethodPrefixInterceptors());
     $classGenerator->addPropertyFromGenerator($suffixInterceptors = new MethodPrefixInterceptors());
     $methods = ProxiedMethodsFilter::getProxiedMethods($originalClass, array('__get', '__set', '__isset', '__unset', '__clone', '__sleep'));
     foreach ($methods as $method) {
         $classGenerator->addMethodFromGenerator(InterceptedMethod::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), $prefixInterceptors, $suffixInterceptors));
     }
     $classGenerator->addMethodFromGenerator(new Constructor($originalClass, $prefixInterceptors, $suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new SetMethodPrefixInterceptor($prefixInterceptors));
     $classGenerator->addMethodFromGenerator(new SetMethodSuffixInterceptor($suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new MagicGet($originalClass, $prefixInterceptors, $suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new MagicSet($originalClass, $prefixInterceptors, $suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new MagicIsset($originalClass, $prefixInterceptors, $suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new MagicUnset($originalClass, $prefixInterceptors, $suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new MagicSleep($originalClass, $prefixInterceptors, $suffixInterceptors));
     $classGenerator->addMethodFromGenerator(new MagicClone($originalClass, $prefixInterceptors, $suffixInterceptors));
 }
 private function buildMethodInterceptor(MethodPrefixInterceptors $prefixInterceptors, MethodSuffixInterceptors $suffixInterceptors) : callable
 {
     return function (ReflectionMethod $method) use($prefixInterceptors, $suffixInterceptors) : InterceptedMethod {
         return InterceptedMethod::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), $prefixInterceptors, $suffixInterceptors);
     };
 }