1 | <?php |
||
29 | class Gatekeeper |
||
30 | { |
||
31 | /** |
||
32 | * @var \Caridea\Acl\Service |
||
33 | */ |
||
34 | private $aclService; |
||
35 | /** |
||
36 | * @var \Caridea\Auth\Principal |
||
37 | */ |
||
38 | private $principal; |
||
39 | /** |
||
40 | * @var array<\Caridea\Acl\Subject> |
||
41 | */ |
||
42 | private $subjects; |
||
43 | |||
44 | /** |
||
45 | * Creates a new Gatekeeper. |
||
46 | * |
||
47 | * @param \Caridea\Acl\Service $aclService The ACL service |
||
48 | * @param \Caridea\Auth\Principal $principal The authenticated principal |
||
49 | * @param array<\Minotaur\Acl\SubjectResolver> $subjectResolvers Any additional subject resolvers |
||
50 | */ |
||
51 | 2 | public function __construct( |
|
66 | |||
67 | /** |
||
68 | * Determines if the currently authenticated user can access the resource. |
||
69 | * |
||
70 | * @param $verb - The verb (e.g. 'read', 'write') |
||
71 | * @param $type - The type of object |
||
72 | * @param $id - The object identifier |
||
73 | * @throws \Caridea\Acl\Exception\Forbidden If the user has no access |
||
74 | */ |
||
75 | 1 | public function assert(string $verb, string $type, $id): void |
|
76 | { |
||
77 | 1 | $this->aclService->assert( |
|
78 | 1 | $this->subjects, |
|
79 | $verb, |
||
80 | 1 | new \Caridea\Acl\Target($type, $id) |
|
81 | ); |
||
82 | 1 | } |
|
83 | |||
84 | /** |
||
85 | * Determines if the currently authenticated user can access the resources. |
||
86 | * |
||
87 | * @param string $verb The verb (e.g. 'read', 'write') |
||
88 | * @param string $type The type of object |
||
89 | * @param iterable<mixed> $ids The object identifiers |
||
90 | * @throws \Caridea\Acl\Exception\Forbidden If the user has no access |
||
91 | */ |
||
92 | public function assertAll(string $verb, string $type, iterable $ids): void |
||
104 | |||
105 | /** |
||
106 | * Determines if the currently authenticated user can access the resource. |
||
107 | * |
||
108 | * @param string $verb The verb (e.g. 'read', 'write') |
||
109 | * @param string $type The type of object |
||
110 | * @param mixed $id The object identifier |
||
111 | * @return bool Whether the user has access |
||
112 | */ |
||
113 | 1 | public function can(string $verb, string $type, $id): bool |
|
121 | } |
||
122 |