Total Complexity | 14 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | class RestrictedResourceVoter |
||
15 | { |
||
16 | private $security; |
||
17 | |||
18 | public function __construct(Security $security) |
||
21 | } |
||
22 | |||
23 | private function rolesVote(array $roles): bool |
||
24 | { |
||
25 | if (!count($roles)) { |
||
26 | return true; |
||
27 | } |
||
28 | $negativeRoles = []; |
||
29 | $positiveRoles = []; |
||
30 | foreach ($roles as $role) { |
||
31 | if (strpos($role, '!') === 0) { |
||
32 | $negativeRoles[] = substr($role, 1); |
||
33 | continue; |
||
34 | } |
||
35 | $positiveRoles[] = $role; |
||
36 | } |
||
37 | $positivePass = count($positiveRoles) && $this->security->isGranted($positiveRoles); |
||
38 | $negativePass = count($negativeRoles) && !$this->security->isGranted($negativeRoles); |
||
39 | return $positivePass || $negativePass; |
||
40 | } |
||
41 | |||
42 | public function isSupported($data): ?RestrictedResourceInterface |
||
43 | { |
||
44 | if ($data instanceof RestrictedResourceInterface && !$data instanceof AbstractContent) { |
||
45 | return $data; |
||
46 | } |
||
47 | return null; |
||
48 | } |
||
49 | |||
50 | public function vote($object): bool |
||
55 | ; |
||
56 | } |
||
57 | } |
||
58 |