1 | <?php |
||
20 | class ThreemaGateway_Handler_Permissions |
||
21 | { |
||
22 | /** |
||
23 | * @var Singleton |
||
24 | */ |
||
25 | protected static $instance = null; |
||
26 | |||
27 | /** |
||
28 | * @var string identifier of the permission group of this addon |
||
29 | */ |
||
30 | const PERMISSION_GROUP = 'threemagw'; |
||
31 | |||
32 | /** |
||
33 | * @var array all possible permissions of this add-on |
||
34 | */ |
||
35 | const PERMISSION_LIST = [ |
||
36 | ['id' => 'use'], |
||
37 | ['id' => 'send'], |
||
38 | ['id' => 'receive'], |
||
39 | ['id' => 'fetch'], |
||
40 | ['id' => 'lookup'], |
||
41 | ['id' => 'tfa'], |
||
42 | // 2FA fast mode |
||
43 | ['id' => 'blockedNotification'], |
||
44 | ['id' => 'blockTfaMode'], |
||
45 | ['id' => 'blockUser'], |
||
46 | ['id' => 'blockIp'], |
||
47 | // admin |
||
48 | [ |
||
49 | 'id' => 'credits', |
||
50 | 'adminOnly' => true, |
||
51 | 'adminName' => 'showcredits' |
||
52 | ] |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * @var array|null User who is using the Threema Gateway |
||
57 | */ |
||
58 | protected $user = null; |
||
59 | |||
60 | /** |
||
61 | * @var array Permissions cache |
||
62 | */ |
||
63 | protected $permissions; |
||
64 | |||
65 | /** |
||
66 | * Private constructor so nobody else can instance it. |
||
67 | * Use {@link getInstance()} instead. |
||
68 | * |
||
69 | * @return true |
||
|
|||
70 | */ |
||
71 | protected function __construct() |
||
75 | |||
76 | /** |
||
77 | * Prevent cloning for Singleton. |
||
78 | */ |
||
79 | protected function __clone() |
||
83 | |||
84 | /** |
||
85 | * SDK startup as a Singleton. |
||
86 | * |
||
87 | * @throws XenForo_Exception |
||
88 | * @return ThreemaGateway_Handler_Permissions |
||
89 | */ |
||
90 | public static function getInstance() |
||
98 | |||
99 | /** |
||
100 | * Sets/Changes the user id of the user using the Threema Gateway. This |
||
101 | * also forces a reload of the permission cache. (See {@link hasPermission()}). |
||
102 | * |
||
103 | * Returns true when value was changed. If false is returned the user is |
||
104 | * already the visitor or the user id is already set or and the value was |
||
105 | * not changed. |
||
106 | * |
||
107 | * @param array|null $newUser (optional) User array |
||
108 | * @return bool |
||
109 | */ |
||
110 | public function setUserId($newUser = null) |
||
145 | |||
146 | /** |
||
147 | * Checks whether the user has the permission to do something. |
||
148 | * |
||
149 | * This uses the user e.g. set by {@link setUserId()}. If no user is set it |
||
150 | * uses the current visitor/user. |
||
151 | * The currently avaliable actions are: use, send, receive, fetch, lookup, |
||
152 | * tfa and credits |
||
153 | * If you do not specify an action an array of all possible actions is |
||
154 | * returned. |
||
155 | * Note that "credits" is an admin permission and is therefore only avaliable |
||
156 | * to admins. |
||
157 | * |
||
158 | * @param string $action (optional) The action you want to do |
||
159 | * @param bool $noCache (optional) Forces the cache to reload |
||
160 | * @return bool|array |
||
161 | */ |
||
162 | public function hasPermission($action = null, $noCache = false) |
||
184 | |||
185 | /** |
||
186 | * Logs an action for checking it via {@link isLimited()} later. |
||
187 | * |
||
188 | * This uses the user e.g. set by {@link setUserId()}. If no user is set it |
||
189 | * uses the current visitor/user. |
||
190 | * |
||
191 | * @param string $action The action the user has done |
||
192 | * @return bool|array |
||
193 | */ |
||
194 | public function logAction($action) |
||
201 | |||
202 | /** |
||
203 | * Checks whether the user has the permission to do something. |
||
204 | * |
||
205 | * This uses the user e.g. set by {@link setUserId()}. If no user is set it |
||
206 | * uses the current visitor/user. |
||
207 | * |
||
208 | * @param string $action The action you want to do |
||
209 | * @return bool|array |
||
210 | */ |
||
211 | public function isLimited($action) |
||
218 | |||
219 | /** |
||
220 | * Reload the permission cache. |
||
221 | * |
||
222 | * @param string $userId the ID of the user |
||
223 | */ |
||
224 | protected function renewCache($userId) |
||
271 | |||
272 | /** |
||
273 | * Returns the current user ID. |
||
274 | * |
||
275 | * @param bool $visitorFallback Optional - If set to false, this does not |
||
276 | * fallback to the current user. |
||
277 | * |
||
278 | * @return int|null |
||
279 | */ |
||
280 | protected function userGetId($visitorFallback = true) |
||
291 | |||
292 | /** |
||
293 | * Checks whether a user is the default user/the current "visitor". |
||
294 | * |
||
295 | * @param int|null $userId A user id or null |
||
296 | * @return bool |
||
297 | */ |
||
298 | protected function userIsDefault($userId) |
||
302 | |||
303 | /** |
||
304 | * Returns the user ID of the current visitor. |
||
305 | * |
||
306 | * @return int |
||
307 | */ |
||
308 | protected function getVisitorUserId() |
||
314 | } |
||
315 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.