api-platform.com's event won't attach to my listener. I tried several combination from their event matrix but it still won't trigger.
# services.yml
user_access_listener:
class: AppBundle\Event\Listener\UserAccessListener
arguments: [ "@security.authorization_checker" ]
tags:
- { name: kernel.event_listener, event: kernel.view, method: onKernelView }
Here is my listener class
namespace 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();
}
}
}
I was expecting "This should trigger" would appear when I hit GET /projects/1
and GET /projects
, but it is not triggering. Thoughts?