예제 #1
0
 protected function processAnnotatedAspect($instance, $reflection)
 {
     $foundAnnotated = false;
     $aspects = $this->config->getAspects();
     foreach ($aspects as $aspect) {
         if (!$aspect->hasAnnotated()) {
             continue;
         }
         $interfaceName = $aspect->getName();
         if ($instance instanceof $interfaceName) {
             $annotated = $aspect->getAnnotated();
             $foundAnnotated = true;
             break;
         } elseif (preg_match("/{$interfaceName}/", $reflection->getName())) {
             $annotated = $aspect->getAnnotated();
             $foundAnnotated = true;
             break;
         }
     }
     if (!$foundAnnotated) {
         return null;
     }
     $weaver = new Sabel_Aspect_Weaver_Static($instance);
     foreach ($reflection->getMethods() as $method) {
         $methodAnnots = $method->getAnnotations();
         foreach ($methodAnnots as $methodAnnotName => $v) {
             if (array_key_exists($methodAnnotName, $annotated)) {
                 $advisor = new Sabel_Aspect_Advisor_RegexMatcherPointcut();
                 $advisor->setClassMatchPattern("/" . $reflection->getName() . "/");
                 $methodName = $method->getName();
                 $interceptor = $annotated[$methodAnnotName][0];
                 $advisor->setMethodMatchPattern("/" . $methodName . "/");
                 $advisor->addAdvice(new $interceptor());
                 $weaver->addAdvisor($advisor);
             }
         }
     }
     return $weaver->getProxy();
 }
예제 #2
0
파일: Proxy.php 프로젝트: reoring/sabel
 public function testPlainObjectPreventBefore()
 {
     $weaver = $this->weaver;
     $advisor = new Sabel_Aspect_Advisor_RegexMatcherPointcut();
     $advisor->setClassMatchPattern("/.+/");
     $advisor->setMethodMatchPattern("/get+/");
     $poAdvice = new Sabel_Tests_Aspect_PlainObject_PreventBeforeAdvice();
     $plainObjectInterceptor = new Sabel_Aspect_Interceptor_PlainObjectAdvice($poAdvice);
     $plainObjectInterceptor->setBeforeAdviceMethod("before");
     $advisor->addAdvice($plainObjectInterceptor);
     $weaver->addAdvisor($advisor);
     $target = $weaver->getProxy();
     $result = $target->getX();
     $this->assertEquals("Y", $result);
 }