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(); }
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; } }