api-platform.com 的事件不会附加到我的听众。我从他们的事件矩阵中尝试了几种组合,但它仍然不会触发。
# services.yml
user_access_listener:
class: AppBundle\Event\Listener\UserAccessListener
arguments: [ "@security.authorization_checker" ]
tags:
- { name: kernel.event_listener, event: kernel.view, method: onKernelView }
这是我的听众课
命名空间 AppBundle\Event\Listener;
use UserBundle\Entity\User;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
class UserAccessListener
{
/**
* @var AuthorizationCheckerInterface
*/
private $authorizationChecker;
/**
* @param AuthorizationCheckerInterface $authorizationChecker
*/
public function __construct(AuthorizationCheckerInterface $authorizationChecker)
{
$this->authorizationChecker = $authorizationChecker;
}
/**
* @param GetResponseForControllerResultEvent $event
*/
public function onKernelView(GetResponseForControllerResultEvent $event)
{
echo "This should trigger";
exit;
$user = $event->getControllerResult();
if (!$user instanceof User) {
return;
}
if (!$this->authorizationChecker->isGranted(null, $user)) {
throw new AccessDeniedException();
}
}
}
GET /projects/1
我期待当我点击and时会出现“这应该触发” GET /projects
,但它没有触发。想法?