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($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(); }
public function testAnnotationPlainObjectAdvice() { $weaver = new Sabel_Aspect_Weaver(); $weaver->build("Sabel_Tests_Aspect_TargetClass", "Sabel_Tests_Aspect_PlainObject_Advice"); $advice = $weaver->getAdvice(); $target = $weaver->getProxy(); $target->getX(); $this->assertEquals("getX", $advice->before); $target->setX("x"); $this->assertEquals("setX", $advice->before); }