/**
  * {@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));
 }
 /**
  * @covers \ProxyManager\Exception\InvalidProxiedClassException::interfaceNotSupported
  */
 public function testInterfaceNotSupported()
 {
     $this->assertSame('Provided interface "ProxyManagerTestAsset\\BaseInterface" cannot be proxied', InvalidProxiedClassException::interfaceNotSupported(new ReflectionClass('ProxyManagerTestAsset\\BaseInterface'))->getMessage());
 }
Exemplo n.º 3
0
 /**
  * @param ReflectionClass $originalClass
  *
  * @return void
  *
  * @throws InvalidProxiedClassException
  */
 private static function isNotInterface(ReflectionClass $originalClass)
 {
     if ($originalClass->isInterface()) {
         throw InvalidProxiedClassException::interfaceNotSupported($originalClass);
     }
 }