private function addMethods(PhpClass $class, array $methods)
 {
     foreach ($methods as $method) {
         $initializingCode = 'if (false === $this->' . $this->prefix . 'initialized) {' . "\n" . '    $this->' . $this->prefix . 'initialize();' . "\n" . '}';
         if ($class->hasMethod($method->name)) {
             $genMethod = $class->getMethod($method->name);
             $genMethod->setBody($initializingCode . "\n" . $genMethod->getBody());
             continue;
         }
         $genMethod = PhpMethod::fromReflection($method);
         $genMethod->setBody($initializingCode . "\n\n" . 'return ' . GeneratorUtils::callMethod($method) . ';');
         $class->setMethod($genMethod);
     }
 }
Exemplo n.º 2
0
 /**
  * Generate aop methods proxies
  *
  * @param PhpClass $aopClass
  * @param PhpClass $parentClass
  */
 private function generateAopMethodProxy(PhpClass $aopClass, PhpClass $parentClass)
 {
     foreach ($parentClass->getMethods() as $method) {
         /* @var $method \CG\Generator\PhpMethod */
         try {
             $aopClass->getMethod($method->getName());
         } catch (\InvalidArgumentException $e) {
             try {
                 $proxyMethod = new ProxyMethod($method);
                 $aopClass->setMethod($proxyMethod);
             } catch (ProxyMethodException $e) {
             }
         }
     }
     if ($parentClass->getParentClassName() != null) {
         $this->generateAopMethodProxy($aopClass, PhpClass::fromReflection(new \ReflectionClass($parentClass->getParentClassName())));
     }
 }