Completed
Pull Request — master (#9)
by
unknown
06:32
created

LogoutController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\Controller;
4
5
use Symfony\Component\HttpFoundation\RedirectResponse;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\Routing\Router;
8
use Symfony\Component\Security\Core\SecurityContext;
9
10
final class LogoutController
11
{
12
    private $securityContext;
13
    private $router;
14
15
    /**
16
     * LogoutController constructor.
17
     *
18
     * @param SecurityContext $securityContext
19
     * @param Router $router
20
     */
21
    public function __construct(SecurityContext $securityContext, Router $router)
22
    {
23
        $this->securityContext = $securityContext;
24
        $this->router = $router;
25
    }
26
27
    /**
28
     * Logout user.
29
     *
30
     * @param Request $request
31
     *
32
     * @return RedirectResponse
33
     */
34
    public function logoutAction(Request $request)
35
    {
36
        $this->securityContext->setToken(null);
37
        $request->getSession()->invalidate();
38
39
        return new RedirectResponse($this->router->generate('login'));
40
    }
41
}
42