Completed
Push — master ( 3ae9e7...e400c0 )
by Jeroen
13:03 queued 06:23
created

AclVoter::vote()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 0
cts 0
cp 0
rs 8.9617
c 0
b 0
f 0
cc 6
nc 9
nop 3
crap 42
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
        $attributeIsSupported = false;
41
        foreach ($attributes as $attribute) {
42
            if ($this->supportsAttribute($attribute)) {
43
                $attributeIsSupported = true;
44
45
                break;
46
            }
47
        }
48
49
        if (!$this->permissionsEnabled && $attributeIsSupported) {
50
            return self::ACCESS_GRANTED;
51
        }
52
53
        if (!$this->permissionsEnabled) {
54
            return self::ACCESS_ABSTAIN;
55
        }
56
57
        return parent::vote($token, $object, $attributes);
58
    }
59
}
60