/** * Constructs functions stub class from namespace Reflection * * @param ReflectionFileNamespace $namespace Reflection of namespace * @param array $advices List of function advices * * @throws \InvalidArgumentException for invalid classes */ public function __construct(ReflectionFileNamespace $namespace, array $advices = []) { parent::__construct($advices); $this->namespace = $namespace; if (empty($advices[AspectContainer::FUNCTION_PREFIX])) { return; } foreach ($advices[AspectContainer::FUNCTION_PREFIX] as $pointName => $value) { $function = new ReflectionFunction($pointName); $this->override($function, $this->getJoinpointInvocationBody($function)); } }
/** * Constructs functions stub class from namespace Reflection * * @param ReflectionFileNamespace $namespace Reflection of namespace * @param array $advices List of function advices * * @throws \InvalidArgumentException for invalid classes */ public function __construct($namespace, array $advices = array()) { if (!$namespace instanceof ReflectionFileNamespace) { throw new \InvalidArgumentException("Invalid argument for namespace"); } parent::__construct($advices); $this->namespace = $namespace; if (empty($advices[AspectContainer::FUNCTION_PREFIX])) { return; } foreach ($advices[AspectContainer::FUNCTION_PREFIX] as $pointName => $value) { $function = new ReflectionFunction($pointName); $this->override($function, $this->getJoinpointInvocationBody($function)); } }
/** * Generates an child code by parent class reflection and joinpoints for it * * @param ReflectionClass $parent Parent class reflection * @param array|Advice[] $classAdvices List of advices for class * * @throws \InvalidArgumentException if there are unknown type of advices */ public function __construct(ReflectionClass $parent, array $classAdvices) { parent::__construct($classAdvices); $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); $this->overrideMethod($method); } break; case AspectContainer::PROPERTY_PREFIX: foreach ($typedAdvices as $joinPointName => $advice) { $property = $parent->getProperty($joinPointName); $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}`"); } } }
/** * Generates an child code by parent class reflection and joinpoints for it * * @param ReflectionClass|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($parent, array $classAdvices, $useStaticForLsb = false) { if (!$parent instanceof ReflectionClass && !$parent instanceof ParsedClass) { throw new \InvalidArgumentException("Invalid argument for class"); } 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) { $this->overrideMethod($parent->getMethod($joinPointName)); } break; case AspectContainer::PROPERTY_PREFIX: foreach ($typedAdvices as $joinPointName => $advice) { $this->interceptProperty($parent->getProperty($joinPointName)); } 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; default: throw new \InvalidArgumentException("Unsupported point `{$type}`"); } } }