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

UserContextInvalidator::invalidateContext()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 1
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 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