/**
  * Get the Pointcut that drives this advisor.
  *
  * @return Pointcut The pointcut
  */
 public function getPointcut()
 {
     if (!$this->pointcut) {
         // Inject this dependencies and make them lazy!
         // should be extracted from AbstractAspectLoaderExtension into separate class
         /** @var Pointcut\PointcutLexer $lexer */
         $lexer = $this->container->get('aspect.pointcut.lexer');
         /** @var Pointcut\PointcutParser $parser */
         $parser = $this->container->get('aspect.pointcut.parser');
         $tokenStream = $lexer->lex($this->pointcutExpression);
         $this->pointcut = $parser->parse($tokenStream);
     }
     return $this->pointcut;
 }
Beispiel #2
0
 /**
  * Configure an AspectContainer with advisors, aspects and pointcuts
  *
  * @param AspectContainer|Container $container
  *
  * @return void
  */
 protected final function configureAop(AspectContainer $container)
 {
     $aspectIds = $container->getParameter('aspect.list');
     foreach ($aspectIds as $aspectId) {
         $container->registerAspect($container->get($aspectId));
     }
 }
 /**
  * Configures an AspectContainer with advisors, aspects and pointcuts
  *
  * @param AspectContainer $container
  *
  * @return void
  */
 protected function configureAop(AspectContainer $container)
 {
     $reader = $container->get('aspect.annotation.reader');
     $container->registerAspect(new InvariantCheckerAspect($reader));
     $container->registerAspect(new PostconditionCheckerAspect($reader));
     $container->registerAspect(new PreconditionCheckerAspect($reader));
 }
 /**
  * Magic accessor
  *
  * @param string $name Key name
  *
  * @throws \InvalidArgumentException if referenced value is not an advisor
  * @return Advice
  */
 public function __get($name)
 {
     if ($this->container->has($name)) {
         $advisor = $this->container->get($name);
     } else {
         list(, $advisorName) = explode('.', $name);
         list($aspect) = explode('->', $advisorName);
         $aspectInstance = $this->container->getAspect($aspect);
         $this->loader->loadAndRegister($aspectInstance);
         $advisor = $this->container->get($name);
     }
     if (!$advisor instanceof Advisor) {
         throw new \InvalidArgumentException("Reference {$name} is not an advisor");
     }
     $this->{$name} = $advisor->getAdvice();
     return $this->{$name};
 }
Beispiel #5
0
 /**
  * Intercepts access to autowired properties and injects specified dependency
  *
  * @Around("@access(Warlock\Annotation\Autowired)")
  *
  * @param FieldAccess $joinpoint Autowiring joinpoint
  *
  * @return mixed
  */
 public function beforeAccessingAutowiredProperty(FieldAccess $joinpoint)
 {
     $obj = $joinpoint->getThis();
     $field = $joinpoint->getField();
     if ($joinpoint->getAccessType() == FieldAccess::READ) {
         /** @var Autowired $autowired */
         $autowired = $this->reader->getPropertyAnnotation($field, self::ANNOTATION_NAME);
         $strategy = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
         if (!$autowired->required) {
             $strategy = ContainerInterface::NULL_ON_INVALID_REFERENCE;
         }
         $value = $this->container->get($autowired, $strategy);
     } else {
         $value = $joinpoint->proceed();
     }
     $field->setValue($obj, $value);
     return $value;
 }
 /**
  * Constructs an wrapper for the composer loader
  *
  * @param ClassLoader $original Instance of current loader
  * @param AspectContainer $container Instance of the container
  * @param array $options Configuration options
  */
 public function __construct(ClassLoader $original, AspectContainer $container, array $options = [])
 {
     $this->options = $options;
     $this->original = $original;
     $prefixes = $original->getPrefixes();
     $excludePaths = $options['excludePaths'];
     // Let's exclude core dependencies from that list
     $excludePaths[] = $prefixes['Dissect'][0];
     $excludePaths[] = substr($prefixes['Doctrine\\Common\\Annotations\\'][0], 0, -16);
     $fileEnumerator = new Enumerator($options['appDir'], $options['includePaths'], $excludePaths);
     $this->fileEnumerator = $fileEnumerator;
     $this->cacheState = $container->get('aspect.cache.path.manager')->queryCacheState();
 }
 /**
  * Collects list of advisors from the container
  *
  * @param AspectContainer $aspectContainer Container instance
  *
  * @return Advisor[] List of advisors in the container
  */
 private function loadAdvisorsList(AspectContainer $aspectContainer)
 {
     /** @var AspectLoader $aspectLoader */
     $aspectLoader = $aspectContainer->get('aspect.cached.loader');
     $aspects = $aspectLoader->getUnloadedAspects();
     foreach ($aspects as $aspect) {
         $aspectLoader->loadAndRegister($aspect);
     }
     $advisors = $aspectContainer->getByTag('advisor');
     return $advisors;
 }
 /**
  * Configures an AspectContainer with advisors, aspects and pointcuts
  *
  * @param AspectContainer $container
  *
  * @return void
  */
 protected function configureAop(AspectContainer $container)
 {
     $reader = $container->get('aspect.annotation.reader');
     $container->registerAspect(new ContractCheckerAspect($reader));
 }