拦截器不适用于JMSAopBundle(Symfony2 AOP)

时间:2013-01-06 11:26:17

标签: php symfony aop

我正试图在Symfony2上做一个方面,但我按照http://jmsyst.com/bundles/JMSAopBundle中的说明操作,我找不到问题所在。这是我的services.yml:

exception_pointcut:
        class:    AGF\Services\Aspects\Exceptions\ExceptionPointcut
        tags:
          - { name: jms_aop.pointcut, interceptor: exception_interceptor }  

exception_interceptor:
        class:    AGF\Services\Aspects\Exceptions\ExceptionInterceptor
        arguments: [@security.context, @logger] 

这是我的“切入点”:

<?php
namespace AGF\Services\Aspects\Exceptions;

use JMS\AopBundle\Aop\PointcutInterface;

class ExceptionPointcut implements PointcutInterface
    {

    public function matchesClass(\ReflectionClass $class) 
        {
        return true;
        }

    public function matchesMethod(\ReflectionMethod $method)
        {

            if($method->name == '__construct')
                {
                return false;   
                }

        }

    }

这是我的拦截器:

<?php
namespace AGF\Services\Aspects\Exceptions;

use CG\Proxy\MethodInterceptorInterface;
use CG\Proxy\MethodInvocation;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;

class ExceptionInterceptor implements MethodInterceptorInterface
    {

    private $context;
    private $logger;

    public function __construct(SecurityContextInterface $context, LoggerInterface $logger)
        {

        $this->context = $context;
        $this->logger = $logger;    
        $this->logger->debug('HOLA2');

        }

    public function intercept(MethodInvocation $invocation) 
        {

        try {
            return $invocation->proceed();
            }   
        catch (\Exception $e)
            {
            $this->logger->err($e);
            }   

        }

    }

所有类都到达切入点,但是没有到达拦截器。当我在切入点(echo $ method-&gt; name)中创建一个“echo”时,切入点可以工作,但是当我在拦截器中进行调试时,日志中没有任何内容。

0 个答案:

没有答案