Completed
Push — master ( e4df22...3ec143 )
by David
04:03
created

UserContextInvalidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 45
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A invalidateContext() 0 9 2
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;
13
14
use FOS\HttpCache\ProxyClient\Invalidation\BanCapable;
15
16
class UserContextInvalidator
17
{
18
    /**
19
     * Service used to ban hash request.
20
     *
21
     * @var BanCapable
22
     */
23
    private $banner;
24
25
    /**
26
     * Accept header.
27
     *
28
     * @var string
29
     */
30
    private $acceptHeader;
31
32
    /**
33
     * User identifier headers.
34
     *
35
     * @var string[]
36
     */
37
    private $userIdentifierHeaders;
38
39 2
    public function __construct(BanCapable $banner, $userIdentifierHeaders, $acceptHeader)
40
    {
41 2
        $this->banner = $banner;
42 2
        $this->acceptHeader = $acceptHeader;
43 2
        $this->userIdentifierHeaders = $userIdentifierHeaders;
44 2
    }
45
46
    /**
47
     * Invalidate the user context hash.
48
     *
49
     * @param string $sessionId
50
     */
51 1
    public function invalidateContext($sessionId)
52
    {
53 1
        foreach ($this->userIdentifierHeaders as $header) {
54 1
            $this->banner->ban([
55 1
                'accept' => $this->acceptHeader,
56 1
                $header => sprintf('.*%s.*', $sessionId),
57
            ]);
58
        }
59 1
    }
60
}
61