1 | <?php |
||
15 | class ServiceAllowedVoter extends Voter |
||
16 | { |
||
17 | /** @var array List of services always allowed to be called. */ |
||
18 | private $whitelist = array(); |
||
19 | |||
20 | /** |
||
21 | * supported classes |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $supportedClasses = [ |
||
26 | 'Symfony\Component\HttpFoundation\Request' |
||
27 | ]; |
||
28 | |||
29 | /** |
||
30 | * supported attributes |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $supportedAttributes = [ |
||
35 | 'VIEW' |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * @param array $whiteList Set of services to be allowed to be called. |
||
40 | */ |
||
41 | 4 | public function __construct($whiteList = array()) |
|
45 | |||
46 | /** |
||
47 | * Determines if the attribute and subject are supported by this voter. |
||
48 | * |
||
49 | * @param string $attribute An attribute |
||
50 | * @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type |
||
51 | * |
||
52 | * @return bool True if the attribute and subject are supported, false otherwise |
||
53 | */ |
||
54 | protected function supports($attribute, $subject) |
||
55 | { |
||
56 | return (isset($this->supportedAttributes[$attribute]) && isset($this->supportedClasses[$subject])); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Perform a single access check operation on a given attribute, subject and token. |
||
61 | * It is safe to assume that $attribute and $subject already passed the "supports()" method check. |
||
62 | * |
||
63 | * @param string $attribute attribute |
||
64 | * @param mixed $subject subject |
||
65 | * @param TokenInterface $token token |
||
66 | * |
||
67 | * @return bool |
||
68 | */ |
||
69 | 2 | protected function voteOnAttribute($attribute, $subject, TokenInterface $token) |
|
73 | } |
||
74 |