Completed
Push — master ( 4758e8...ddc8c1 )
by David de
03:36
created

ContextInvalidationLogoutHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCacheBundle\Security\Http\Logout;
13
14
use FOS\HttpCache\ProxyClient\Invalidation\BanCapable;
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpFoundation\Response;
17
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
18
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
19
20
class ContextInvalidationLogoutHandler implements LogoutHandlerInterface
21
{
22
    /**
23
     * Service used to ban hash request.
24
     *
25
     * @var \FOS\HttpCache\ProxyClient\Invalidation\BanCapable
26
     */
27
    private $banner;
28
29
    /**
30
     * Accept header.
31
     *
32
     * @var string
33
     */
34
    private $acceptHeader;
35
36
    /**
37
     * User identifier headers.
38
     *
39
     * @var string[]
40
     */
41
    private $userIdentifierHeaders;
42
43 1
    public function __construct(BanCapable $banner, $userIdentifierHeaders, $acceptHeader)
44
    {
45 1
        $this->banner = $banner;
46 1
        $this->acceptHeader = $acceptHeader;
47 1
        $this->userIdentifierHeaders = $userIdentifierHeaders;
48 1
    }
49
50
    /**
51
     * Invalidate the user context hash.
52
     *
53
     * @param Request        $request
54
     * @param Response       $response
55
     * @param TokenInterface $token
56
     */
57 1
    public function logout(Request $request, Response $response, TokenInterface $token)
58
    {
59 1
        $sessionId = $request->getSession()->getId();
60
61 1
        foreach ($this->userIdentifierHeaders as $header) {
62 1
            $this->banner->ban([
63 1
                'accept' => $this->acceptHeader,
64 1
                $header => sprintf('.*%s.*', $sessionId),
65
            ]);
66
        }
67 1
    }
68
}
69