/** * Adds or overwrites the given aspect. * * @param AspectDefinition $aspect Aspect. * * @return void */ public function setAspect(AspectDefinition $aspect) { $name = $aspect->getName(); $this->_aspects[$name] = $aspect; $this->_cache->store('AspectManagerAspect' . $name, $aspect); $this->_cache->store('Aspects', $this->_aspects); }
/** * Will inject into the given dispatcher the necessary information to * aspects will be run correctly. * * @throws BeanFactoryException * @return void */ private function _applyAspect($targetClass, AspectDefinition $aspectDefinition, IDispatcher $dispatcher) { $rClass = $this->_reflectionFactory->getClass($targetClass); $aspect = $this->getBean($aspectDefinition->getBeanName()); foreach ($aspectDefinition->getPointcuts() as $pointcutName) { $pointcut = $this->_aspectManager->getPointcut($pointcutName); if ($pointcut === false) { throw new BeanFactoryException('Could not find pointcut: ' . $pointcutName); } $expression = $pointcut->getExpression(); foreach ($rClass->getMethods() as $method) { $methodName = $method->getName(); if (preg_match('/' . $expression . '/', $methodName) === 0) { continue; } if ($aspectDefinition->getType() == AspectDefinition::ASPECT_METHOD) { $dispatcher->addMethodInterceptor($methodName, $aspect, $pointcut->getMethod()); } else { $dispatcher->addExceptionInterceptor($methodName, $aspect, $pointcut->getMethod()); } } } }