我正试图在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”时,切入点可以工作,但是当我在拦截器中进行调试时,日志中没有任何内容。