public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        if (!$this->csrfTokenManager instanceof CsrfTokenManagerInterface) {
            return;
        }

        $request = $event->getRequest();

        if ($request->isMethodCacheable()) {
            return;
        }

        if ($request->attributes->get('_route') !== $this->routeName) {
            return;
        }

        $session = $event->getRequest()->getSession();
        if (!$session->isStarted()) {
            return;
        }

        if ($request->headers->get('X-CSRF-Token') !== null) {
            return;
        }

        $csrfToken = $this->csrfTokenManager->getToken($this->csrfTokenId)->getValue();

        $request->headers->set('X-CSRF-Token', $csrfToken);
    }
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        if (!$this->csrfTokenManager instanceof CsrfTokenManagerInterface) {
            return;
        }

        $request = $event->getRequest();

        if ($request->isMethodCacheable()) {
            return;
        }

        if ($request->attributes->get('_route') !== $this->routeName) {
            return;
        }

        $session = $event->getRequest()->getSession();
        if (!$session->isStarted()) {
            return;
        }

        if ($request->headers->get('X-CSRF-Token') !== null) {
            return;
        }

        $csrfToken = $this->csrfTokenManager->getToken($this->csrfTokenId)->getValue();

        $request->headers->set('X-CSRF-Token', $csrfToken);
    }
public function onKernelRequest ( GetResponseEvent $ event ) { if ( ! $ event -> isMasterRequest ( ) ) { return ; } if ( ! $ this -> csrfTokenManager instanceof CsrfTokenManagerInterface ) { return ; } $ request = $ event -> getRequest ( ) ; if ( $ request -> isMethodCacheable ( ) ) { return ; } if ( $ request -> attributes -> get ( '_route' ) !== $ this -> routeName ) { return ; } $ session = $ event -> getRequest ( ) -> getSession ( ) ; if ( ! $ session -> isStarted ( ) ) { return ; } if ( $ request -> headers -> get ( 'X-CSRF-Token' ) !== null ) { return ; } $ csrfToken = $ this -> csrfTokenManager -> getToken ( $ this -> csrfTokenId ) -> getValue ( ) ; $ request -> headers -> set ( 'X-CSRF-Token' , $ csrfToken ) ; }
Resolves the layout to be used for the current request.

@param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
Resolves the layout to be used for the current request .