1 | <?php |
||
29 | class Rule |
||
30 | { |
||
31 | /** |
||
32 | * @var \Caridea\Acl\Subject The subject |
||
33 | */ |
||
34 | private $subject; |
||
35 | /** |
||
36 | * @var array|null An array of verbs granted access, or null for all verbs |
||
37 | */ |
||
38 | private $verbs; |
||
39 | /** |
||
40 | * @var bool Whether the Subject is allowed or forbidden |
||
41 | */ |
||
42 | private $allowed; |
||
43 | |||
44 | /** |
||
45 | * Creates a new Rule. |
||
46 | * |
||
47 | * @param \Caridea\Acl\Subject $subject The subject |
||
48 | * @param bool $allowed Whether this is an allowing rule |
||
49 | * @param array<string>|null $verbs Array of verbs, or `null` for all verbs |
||
50 | */ |
||
51 | 2 | protected function __construct(Subject $subject, bool $allowed, array $verbs = null) |
|
57 | |||
58 | /** |
||
59 | * Gets whether this is an allowing rule. |
||
60 | * |
||
61 | * @return bool Whether this is an allowing rule |
||
62 | */ |
||
63 | 2 | public function isAllowed(): bool |
|
67 | |||
68 | /** |
||
69 | * Gets whether this Rule matches the `Subject` and verb provided. |
||
70 | * |
||
71 | * @param \Caridea\Acl\Subject $subject The subject to check |
||
72 | * @param string $verb The verb to check |
||
73 | * @return bool Whether this Rule matches the arguments provided |
||
74 | */ |
||
75 | 2 | public function match(Subject $subject, string $verb): bool |
|
81 | |||
82 | /** |
||
83 | * Creates an allowing Rule. |
||
84 | * |
||
85 | * @param \Caridea\Acl\Subject $subject The subject to allow access |
||
86 | * @param array<string>|null $verbs Optional list of allowed verbs. |
||
87 | * Empty or `null` means *all*. |
||
88 | * @return Rule The allowing Rule |
||
89 | */ |
||
90 | 1 | public static function allow(Subject $subject, array $verbs = null): Rule |
|
94 | |||
95 | /** |
||
96 | * Creates an denying Rule. |
||
97 | * |
||
98 | * @param \Caridea\Acl\Subject $subject The subject to allow access |
||
99 | * @param array<string>|null $verbs Optional list of denied verbs. |
||
100 | * Empty or `null` means *all*. |
||
101 | * @return Rule The denying Rule |
||
102 | */ |
||
103 | 1 | public static function deny(Subject $subject, array $verbs = null): Rule |
|
107 | } |
||
108 |