public function __call($method, $arg) { $reflection = new Sabel_Reflection_Class($this->target); if ($this->checkTargetMethod && !$reflection->hasMethod($method)) { throw new Sabel_Aspect_Exception_MethodNotFound($method . " not found"); } $this->invocation->reset($method, $arg); $advices = array(); $pointcuts = new Sabel_Aspect_DefaultPointcuts(); foreach ($this->advisor as $advisor) { $pointcut = $advisor->getPointcut(); if (!$pointcut instanceof Sabel_Aspect_Pointcut) { throw new Sabel_Exception_Runtime("pointcut must be Sabel_Aspect_Pointcut"); } if ($pointcuts->matches($pointcut, $method, $this->target)) { $advice = $advisor->getAdvice(); if (is_array($advice)) { $advices = array_merge($advice, $advices); } else { $advices[] = $advice; } } } if (count($advices) >= 1) { $this->invocation->setAdvices($advices); } return $this->invocation->proceed(); }
protected function doFixture($method) { $name = $this->name === "" ? get_class($this) : $this->name; $fixtureDir = RUN_BASE . DS . "tests" . DS . "fixture"; $reflection = new Sabel_Reflection_Class($name); $annotation = $reflection->getAnnotation("fixture"); if (isset($annotation[0])) { if ($method === "downFixture") { $annotation[0] = array_reverse($annotation[0]); } try { foreach ($annotation[0] as $fixtureName) { Sabel::fileUsing($fixtureDir . DS . $this->getFixturePath($fixtureName), true); $className = "Fixture_" . $fixtureName; $fixture = new $className(); $fixture->{$method}(); } } catch (Exception $e) { if ($reflection->hasMethod($method . "Exception")) { $reflection->getMethod($method . "Exception")->invoke(null, $e); } else { throw $e; } } } }
private function _build($adviceClass) { $this->advice = $advice = new $adviceClass(); if (isset(self::$reflectionCache[$adviceClass])) { $reflection = self::$reflectionCache[$adviceClass]; } else { $reflection = new Sabel_Reflection_Class($advice); self::$reflectionCache[$adviceClass] = $reflection; } $annotatedAdvisor = $reflection->getAnnotation("advisor"); if ($annotatedAdvisor !== null) { $this->advisorClass = $annotatedAdvisor[0][0]; } $annotatedInterceptor = $reflection->getAnnotation("interceptor"); if ($annotatedInterceptor !== null) { $this->interceptorClass = $annotatedInterceptor[0][0]; } $annotatedClass = $reflection->getAnnotation("classMatch"); if ($annotatedClass !== null) { $this->annotatedClass = $annotatedClass[0][0]; } foreach ($reflection->getMethods() as $method) { $this->addToAdvisor($method, $advice); } }
public function build($weaverClass, $targetClass, $adviceClasses) { $this->weaver = new $weaverClass($targetClass); if (!is_array($adviceClasses)) { $adviceClasses = array($adviceClasses); } $adviceClasses = array_reverse($adviceClasses); foreach ($adviceClasses as $adviceClass) { $advice = new $adviceClass(); $this->advice = $advice; $reflection = new Sabel_Reflection_Class($advice); $annotatedAdvisor = $reflection->getAnnotation("advisor"); if ($annotatedAdvisor !== null) { $this->advisorClass = $annotatedAdvisor[0][0]; } $annotatedInterceptor = $reflection->getAnnotation("interceptor"); if ($annotatedInterceptor !== null) { $this->interceptorClass = $annotatedInterceptor[0][0]; } $annotatedClass = $reflection->getAnnotation("classMatch"); if ($annotatedClass !== null) { $this->annotatedClass = $annotatedClass[0][0]; } foreach ($reflection->getMethods() as $method) { $this->addToAdvisor($method); } } return $this->weaver; }
public function __call($method, $arg) { $reflection = new Sabel_Reflection_Class($this->target); if ($this->checkTargetMethod && !$reflection->hasMethod($method)) { throw new Sabel_Aspect_Exception_MethodNotFound($method . " not found"); } $this->invocation->reset($method, $arg); if ($this->adviced->hasAdvice($method)) { $this->invocation->setAdvices($this->adviced->getAdvice($method)); } return $this->invocation->proceed(); }
public function getProxy() { if ($this->target === null) { throw new Sabel_Exception_Runtime("must be set target class"); } if (!is_object($this->target)) { if (class_exists($this->target)) { $this->target = new $this->target(); } } $adviced = new Sabel_Aspect_Adviced(); $reflection = new Sabel_Reflection_Class($this->target); foreach ($this->advisor as $advisor) { if (!$advisor instanceof Sabel_Aspect_Advisor) { throw new Sabel_Exception_Runtime("advisor must be implements Sabel_Aspect_Advisor"); } $pointcut = $advisor->getPointcut(); if (!$pointcut instanceof Sabel_Aspect_Pointcut) { throw new Sabel_Exception_Runtime("pointcut must be Sabel_Aspect_Pointcut"); } $pointcuts = new Sabel_Aspect_DefaultPointcuts(); foreach ($reflection->getMethods() as $method) { if ($pointcuts->matches($pointcut, $method->getName(), $this->target)) { $adviced->addAdvices($method->getName(), $advisor->getAdvice()); } } } if ($adviced->hasAdvices()) { $proxy = new Sabel_Aspect_Proxy_Static($this->target); $proxy->__setAdviced($adviced); return $proxy; } else { // no match found. return a raw target object. return $this->target; } }