symfony2 检查 kernelRequest 请求是否是 assetic
symfony2 check on kernelRequest if the request is an assetic
我需要在 onKernelRequest eventListener 上知道请求是否是资产路由。
我该怎么做?我热了这个听众:
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
// Here i need check if the request owns to an assetic
if ($this->authorizationChecker->isGranted('ROLE_USER'))
{
// do something...
}
else
{
}
}
根据AsseticLoader第116行,assetic生成的路由似乎总是包含字符串'_assetic_'
。所以你应该检查匹配的路由是否不包含该字符串。例如:
// in your listener:
// return from the listener if this as an assetic route
if ( strpos($event->getRequest()->attributes->get('_route'), 'assetic') !== false)
return;
我需要在 onKernelRequest eventListener 上知道请求是否是资产路由。
我该怎么做?我热了这个听众:
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
// Here i need check if the request owns to an assetic
if ($this->authorizationChecker->isGranted('ROLE_USER'))
{
// do something...
}
else
{
}
}
根据AsseticLoader第116行,assetic生成的路由似乎总是包含字符串'_assetic_'
。所以你应该检查匹配的路由是否不包含该字符串。例如:
// in your listener:
// return from the listener if this as an assetic route
if ( strpos($event->getRequest()->attributes->get('_route'), 'assetic') !== false)
return;