FirewallSubscriber   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A onPresenter() 0 8 2
A __construct() 0 5 1
A getSubscribedEvents() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symnedi.
7
 * Copyright (c) 2014 Tomas Votruba (http://tomasvotruba.cz)
8
 */
9
10
namespace Symnedi\Security\EventSubscriber;
11
12
use Nette\Http\IRequest;
13
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14
use Symnedi\EventDispatcher\Event\ApplicationPresenterEvent;
15
use Symnedi\EventDispatcher\NetteApplicationEvents;
16
use Symnedi\Security\Contract\Http\FirewallHandlerInterface;
17
use Symnedi\Security\Contract\Http\FirewallMapInterface;
18
19
/**
20
 * Mimics @see \Symfony\Component\Security\Http\Firewall.
21
 */
22
final class FirewallSubscriber implements EventSubscriberInterface
23
{
24
    /**
25
     * @var FirewallMapInterface
26
     */
27
    private $firewallMap;
28
29
    /**
30
     * @var IRequest
31
     */
32
    private $request;
33
34 3
    public function __construct(FirewallMapInterface $firewallMap, IRequest $request)
35
    {
36 3
        $this->firewallMap = $firewallMap;
37 3
        $this->request = $request;
38 3
    }
39
40 2
    public static function getSubscribedEvents() : array
41
    {
42
        return [
43 2
            NetteApplicationEvents::ON_PRESENTER => 'onPresenter',
44
        ];
45
    }
46
47 2
    public function onPresenter(ApplicationPresenterEvent $applicationPresenterEvent)
48
    {
49
        /** @var FirewallHandlerInterface[] $listeners */
50 2
        list($listeners) = $this->firewallMap->getListeners($this->request);
51 2
        foreach ($listeners as $listener) {
52 2
            $listener->handle($applicationPresenterEvent->getApplication(), $this->request);
53
        }
54 1
    }
55
}
56