Esempio n. 1
0
 public function testComplexComposition()
 {
     $lexer = new PointcutLexer();
     $parser = new PointcutParser();
     $tok = $lexer->tokenize('execution(@Transactional *()) || (within(@Transactional *) && execution(*()))');
     $or = $parser->parse($tok);
     $this->assertTrue($or instanceof OrPointcut);
     $execution = $or->getFilter1();
     $this->assertTrue($execution instanceof ExecutionPointcut);
     $this->assertEquals('*', $execution->getNamePattern());
     $this->assertCount(1, $execution->getAnnotationFilters());
     $this->assertEquals(['Transactional'], $execution->getAnnotationFilters()[0]->getAnnotations());
     $and = $or->getFilter2();
     $this->assertTrue($and instanceof AndPointcut);
     $within = $and->getFilter1();
     $this->assertTrue($within instanceof TypePointcut);
     $this->assertEquals('*', $within->getNamePattern());
     $this->assertCount(1, $within->getAnnotationFilters());
     $this->assertEquals(['Transactional'], $within->getAnnotationFilters()[0]->getAnnotations());
     $execution = $and->getFilter2();
     $this->assertTrue($execution instanceof ExecutionPointcut);
     $this->assertEquals('*', $execution->getNamePattern());
     $this->assertEmpty($execution->getAnnotationFilters());
 }
Esempio n. 2
0
 protected function loadAdvisors($aspectType, TypeInfoManagerInterface $manager)
 {
     $type = $manager->getTypeInfo($aspectType);
     $lexer = new Pointcut\PointcutLexer();
     $parser = new Pointcut\PointcutParser();
     foreach ($this->collectMethods($type, $manager) as $method) {
         if (!$method->isPublic()) {
             continue;
         }
         if ($method->isStatic()) {
             continue;
         }
         if ($method->isAbstract()) {
             continue;
         }
         $annotations = $method->getAnnotations();
         $exposeThis = NULL;
         $exposeArgs = NULL;
         $exposeReturns = NULL;
         // 			foreach($annotations as $anno)
         // 			{
         // 				if($anno instanceof Expose)
         // 				{
         // 					$pointcut = $parser->parse($lexer->tokenize($anno->value), $this->createPointcutContext($type, $method));
         // 					$exposeThis = $this->findThis($pointcut);
         // 					$args = $this->findArgs($pointcut);
         // 					$exposeArgs = ($args instanceof ArgsPointcut) ? $args->getMapping() : NULL;
         // 					$exposeReturns = $this->findReturns($pointcut);
         // 					break;
         // 				}
         // 			}
         foreach ($annotations as $anno) {
             if ($anno instanceof Before) {
                 $context = $this->createPointcutContext($type, $method);
                 $pointcut = $parser->parse($lexer->tokenize($anno->value), $context);
                 $interceptor = new ContainerInterceptor($type->getName(), $method->getName(), $context, $exposeThis, $exposeArgs, $exposeReturns);
                 $advice = new BeforeAdvice($interceptor, $anno->order);
                 $this->advisors[] = new Advisor(Advisor::TARGET_ELEMENT, $advice, $pointcut);
             }
             if ($anno instanceof Around) {
                 $context = $this->createPointcutContext($type, $method);
                 $pointcut = $parser->parse($lexer->tokenize($anno->value), $context);
                 $interceptor = new ContainerInterceptor($type->getName(), $method->getName(), $context, $exposeThis, $exposeArgs, $exposeReturns);
                 $advice = new AroundAdvice($interceptor, $anno->order);
                 $this->advisors[] = new Advisor(Advisor::TARGET_ELEMENT, $advice, $pointcut);
             }
             if ($anno instanceof After) {
                 $context = $this->createPointcutContext($type, $method);
                 $pointcut = $parser->parse($lexer->tokenize($anno->value), $context);
                 $interceptor = new ContainerInterceptor($type->getName(), $method->getName(), $context, $exposeThis, $exposeArgs, $exposeReturns);
                 $advice = new AfterAdvice($interceptor, $anno->order);
                 $this->advisors[] = new Advisor(Advisor::TARGET_ELEMENT, $advice, $pointcut);
             }
         }
     }
 }