Ding\Container\Impl\ContainerImpl::_applyAspect PHP Method

_applyAspect() private method

Will inject into the given dispatcher the necessary information to aspects will be run correctly.
private _applyAspect ( $targetClass, Ding\Aspect\AspectDefinition $aspectDefinition, Ding\Aspect\Interceptor\IDispatcher $dispatcher ) : void
$aspectDefinition Ding\Aspect\AspectDefinition
$dispatcher Ding\Aspect\Interceptor\IDispatcher
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());
                }
            }
        }
    }