Completed
Push — master ( df23c5...76ef21 )
by Jeroen
31s queued 12s
created

AclVoter::vote()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 6
1
<?php
2
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
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 Kunstmaan\AdminBundle\Helper\Security\Acl\Voter;
13
14
use Psr\Log\LoggerInterface;
15
use Symfony\Component\Security\Acl\Model\AclProviderInterface;
16
use Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface;
17
use Symfony\Component\Security\Acl\Model\SecurityIdentityRetrievalStrategyInterface;
18
use Symfony\Component\Security\Acl\Permission\PermissionMapInterface;
19
use Symfony\Component\Security\Acl\Voter\AclVoter as BaseAclVoter;
20
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
21
22
/**
23
 * This voter can be used as a base class for implementing your own permissions.
24
 *
25
 * @author Johannes M. Schmitt <[email protected]>
26
 */
27
class AclVoter extends BaseAclVoter
28 1
{
29
    /** @var bool */
30 1
    private $permissionsEnabled;
31 1
32
    public function __construct(AclProviderInterface $aclProvider, ObjectIdentityRetrievalStrategyInterface $oidRetrievalStrategy, SecurityIdentityRetrievalStrategyInterface $sidRetrievalStrategy, PermissionMapInterface $permissionMap, LoggerInterface $logger = null, $allowIfObjectIdentityUnavailable = true, $permissionsEnabled = true)
33
    {
34
        parent::__construct($aclProvider, $oidRetrievalStrategy, $sidRetrievalStrategy, $permissionMap, $logger, $allowIfObjectIdentityUnavailable);
35
        $this->permissionsEnabled = $permissionsEnabled;
36
    }
37
38
    public function vote(TokenInterface $token, $object, array $attributes)
39
    {
40
        if (!$this->permissionsEnabled) {
41
            return self::ACCESS_GRANTED;
42
        }
43
44
        return parent::vote($token, $object, $attributes);
45
    }
46
}
47