public function logout(Request $request)
    {
        $event = new AccessControlEvent($request);
        /** @var Token $sessionAuth */
        $sessionAuth = $this->session()->get('authentication');
        $userId = $sessionAuth ? $sessionAuth->getToken()->getUserId() : false;
        if ($userId && $sessionAuth->getUser()) {
            $userName = $sessionAuth->getUser()->getUsername();
            $this->app['logger.system']->info('Logged out: ' . $userName, ['event' => 'authentication']);
            $event->setUserName($userName);
        }
        $this->app['dispatcher']->dispatch(AccessControlEvents::LOGOUT_SUCCESS, $event);

        // Clear the session
        $this->accessControl()->revokeSession();
        $this->session()->invalidate(-1);

        // Clear cookie data
        $response = $this->redirectToRoute('login');
        $response->headers->clearCookie(
            $this->app['token.authentication.name'],
            $request->getBasePath(),
            $this->getOption('general/cookies_domain'),
            $this->getOption('general/enforce_ssl')
        );

        return $response;
    }
public function logout(Request $request)
    {
        $event = new AccessControlEvent($request);
        /** @var Token $sessionAuth */
        $sessionAuth = $this->session()->get('authentication');
        $userId = $sessionAuth ? $sessionAuth->getToken()->getUserId() : false;
        if ($userId && $sessionAuth->getUser()) {
            $userName = $sessionAuth->getUser()->getUsername();
            $this->app['logger.system']->info('Logged out: ' . $userName, ['event' => 'authentication']);
            $event->setUserName($userName);
        }
        $this->app['dispatcher']->dispatch(AccessControlEvents::LOGOUT_SUCCESS, $event);

        // Clear the session
        $this->accessControl()->revokeSession();
        $this->session()->invalidate(-1);

        // Clear cookie data
        $response = $this->redirectToRoute('login');
        $response->headers->clearCookie(
            $this->app['token.authentication.name'],
            $request->getBasePath(),
            $this->getOption('general/cookies_domain'),
            $this->getOption('general/enforce_ssl')
        );

        return $response;
    }
public function logout ( Request $ request ) { $ event = new AccessControlEvent ( $ request ) ; /** @var Token $sessionAuth */ $ sessionAuth = $ this -> session ( ) -> get ( 'authentication' ) ; $ userId = $ sessionAuth ? $ sessionAuth -> getToken ( ) -> getUserId ( ) : false ; if ( $ userId && $ sessionAuth -> getUser ( ) ) { $ userName = $ sessionAuth -> getUser ( ) -> getUsername ( ) ; $ this -> app [ 'logger.system' ] -> info ( 'Logged out: ' . $ userName , [ 'event' => 'authentication' ] ) ; $ event -> setUserName ( $ userName ) ; } $ this -> app [ 'dispatcher' ] -> dispatch ( AccessControlEvents :: LOGOUT_SUCCESS , $ event ) ; // Clear the session $ this -> accessControl ( ) -> revokeSession ( ) ; $ this -> session ( ) -> invalidate ( - 1 ) ; // Clear cookie data $ response = $ this -> redirectToRoute ( 'login' ) ; $ response -> headers -> clearCookie ( $ this -> app [ 'token.authentication.name' ] , $ request -> getBasePath ( ) , $ this -> getOption ( 'general/cookies_domain' ) , $ this -> getOption ( 'general/enforce_ssl' ) ) ; return $ response ; }
Logout page.

@param Request $request

@return RedirectResponse
Logout page .