Пример #1
0
 /**
  * Generates an child code by parent class reflection and joinpoints for it
  *
  * @param ParsedClass $parent Parent class reflection
  * @param array|Advice[] $classAdvices List of advices for class
  * @param bool $useStaticForLsb Should proxy use 'static::class' instead of '\get_called_class()'
  *
  * @throws \InvalidArgumentException if there are unknown type of advices
  * @return ClassProxy
  */
 public function __construct(ParsedClass $parent, array $classAdvices, $useStaticForLsb = false)
 {
     parent::__construct($classAdvices, $useStaticForLsb);
     $this->class = $parent;
     $this->name = $parent->getShortName();
     $this->parentClassName = $parent->getShortName();
     $this->addInterface('\\Go\\Aop\\Proxy');
     $this->addJoinpointsProperty();
     foreach ($classAdvices as $type => $typedAdvices) {
         switch ($type) {
             case AspectContainer::METHOD_PREFIX:
             case AspectContainer::STATIC_METHOD_PREFIX:
                 foreach ($typedAdvices as $joinPointName => $advice) {
                     $method = $parent->getMethod($joinPointName);
                     if (!$method instanceof ParsedMethod) {
                         continue;
                     }
                     $this->overrideMethod($method);
                 }
                 break;
             case AspectContainer::PROPERTY_PREFIX:
                 foreach ($typedAdvices as $joinPointName => $advice) {
                     $property = $parent->getProperty($joinPointName);
                     if (!$property instanceof ParsedProperty) {
                         continue;
                     }
                     $this->interceptProperty($property);
                 }
                 break;
             case AspectContainer::INTRODUCTION_TRAIT_PREFIX:
                 foreach ($typedAdvices as $advice) {
                     /** @var $advice IntroductionInfo */
                     foreach ($advice->getInterfaces() as $interface) {
                         $this->addInterface($interface);
                     }
                     foreach ($advice->getTraits() as $trait) {
                         $this->addTrait($trait);
                     }
                 }
                 break;
             case AspectContainer::INIT_PREFIX:
             case AspectContainer::STATIC_INIT_PREFIX:
                 break;
                 // No changes for class
             // No changes for class
             default:
                 throw new \InvalidArgumentException("Unsupported point `{$type}`");
         }
     }
 }