Completed
Pull Request — master (#394)
by Wesley
03:51
created

UserContextInvalidator::__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 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 1
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;
13
14
use FOS\HttpCache\ProxyClient\Invalidation\BanCapable;
15
16
class UserContextInvalidator
17
{
18
    /**
19
     * Service used to ban hash request.
20
     *
21
     * @var \FOS\HttpCache\ProxyClient\Invalidation\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