Completed
Push — master ( 2e8f5e...e386fe )
by David
03:04
created

SwitchUserListener::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\EventListener;
13
14
use FOS\HttpCacheBundle\UserContextInvalidator;
15
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
use Symfony\Component\Security\Http\Event\SwitchUserEvent;
17
use Symfony\Component\Security\Http\SecurityEvents;
18
19
class SwitchUserListener implements EventSubscriberInterface
20
{
21
    private $invalidator;
22
23 3
    public function __construct(UserContextInvalidator $invalidator)
24
    {
25 3
        $this->invalidator = $invalidator;
26 3
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 2
    public static function getSubscribedEvents(): array
32
    {
33
        return [
34 2
            SecurityEvents::SWITCH_USER => 'onSwitchUser',
35
        ];
36
    }
37
38 2
    public function onSwitchUser(SwitchUserEvent $event)
39
    {
40 2
        $request = $event->getRequest();
41 2
        $this->invalidator->invalidateContext($request->getSession()->getId());
42 2
    }
43
}
44