0

I have implemented a onKernelRequest handler:

class RequestSubscriber implements EventSubscriberInterface
{

    public static function getSubscribedEvents ()
    {
        return array (
          KernelEvents::REQUEST => [array ('onKernelRequest', 5000)]
        );
    }

    public function onKernelRequest (GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $request->attributes->set('_controller', 'TestBundle:Display:index');
    }

}

For the sake of brevity I removed the conditional testing that goes into checking whether the controller should be overridden.

This works - except that the debug toolbar doesn't show now - and I assume all the other listeners/subscribers to this and kernel.controller are circumvented now as well???

Will this work better if I did it kernel.controller event instead? As the last handler with a higher priority?

Alex.Barylski
  • 2,843
  • 4
  • 45
  • 68
  • You assume wrong. The posted code is not going to circumvent anything. You have something else going on. – Cerad Jul 23 '17 at 17:59
  • OK good to know - any idea as to what might be at play? The code works as I hoped but the fact the debug bar suddenly stops when I call that final line??? – Alex.Barylski Jul 23 '17 at 18:01
  • Weird...it suddenly seems to be working again...removing the conditional tests from the set() seems to cause the havoc. Once those are back in place it all seems fine. – Alex.Barylski Jul 23 '17 at 18:07

0 Answers0