CheckRequirementsSubscriber::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

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 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify.
7
 * Copyright (c) 2014 Tomas Votruba (http://tomasvotruba.cz)
8
 */
9
10
namespace Symplify\SymfonySecurity\EventSubscriber;
11
12
use Nette\Application\UI\ComponentReflection;
13
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
15
use Symplify\SymfonyEventDispatcher\Adapter\Nette\Event\PresenterCreatedEvent;
16
17
final class CheckRequirementsSubscriber implements EventSubscriberInterface
18
{
19
    /**
20
     * @var AuthorizationCheckerInterface
21
     */
22
    private $authorizationChecker;
23
24 1
    public function __construct(AuthorizationCheckerInterface $authorizationChecker)
25
    {
26 1
        $this->authorizationChecker = $authorizationChecker;
27 1
    }
28
29 1
    public static function getSubscribedEvents() : array
30
    {
31
        return [
32 1
            PresenterCreatedEvent::NAME => 'onPresenter',
33
        ];
34
    }
35
36 1
    public function onPresenter(PresenterCreatedEvent $applicationPresenterEvent)
37
    {
38 1
        $this->authorizationChecker->isGranted(
39 1
            'access',
40 1
            new ComponentReflection($applicationPresenterEvent->getPresenter())
41
        );
42 1
    }
43
}
44