2

我正在尝试在 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->name)中进行“回声”时,切入点起作用,但是当我在拦截器中进行调试时,日志中没有任何内容。

4

0 回答 0