Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Permission | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
| create | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This class manages user permissions and group memberships. |
| 5 | * |
| 6 | * There are currently two possible extensions of this class: basic and medium by the |
| 7 | * classes BasicPermission and MediumPermission. |
| 8 | * |
| 9 | * The permission type can be selected by calling the static method $perm = Permission::create($permLevel) |
| 10 | * where $permLevel is 'medium'. |
| 11 | * |
| 12 | * Perhaps the most important method is $perm->hasPermission(right_name). |
| 13 | * This checks whether the user has the user_id set with $perm->setPerm() |
| 14 | * The permission object is added to a user using the user's addPerm() method. |
| 15 | * A single permission-object is allowed for each user. |
| 16 | * The permission-object is in the user's $perm variable. |
| 17 | * Permission methods are performed using the variable (e.g., $user->perm->method()). |
| 18 | * |
| 19 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 20 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 21 | * obtain one at https://mozilla.org/MPL/2.0/. |
| 22 | * |
| 23 | * @package phpMyFAQ |
| 24 | * @author Lars Tiedemann <php@larstiedemann.de> |
| 25 | * @copyright 2005-2026 phpMyFAQ Team |
| 26 | * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 27 | * @link https://www.phpmyfaq.de |
| 28 | * @since 2005-09-17 |
| 29 | */ |
| 30 | |
| 31 | declare(strict_types=1); |
| 32 | |
| 33 | namespace phpMyFAQ; |
| 34 | |
| 35 | use InvalidArgumentException; |
| 36 | use phpMyFAQ\Permission\BasicPermission; |
| 37 | use phpMyFAQ\Permission\MediumPermission; |
| 38 | use phpMyFAQ\Permission\PermissionInterface; |
| 39 | |
| 40 | class Permission |
| 41 | { |
| 42 | /** |
| 43 | * Permission::create() returns an instance of an implementation of the Permission interface. |
| 44 | */ |
| 45 | public static function create(string $permLevel, Configuration $configuration): PermissionInterface |
| 46 | { |
| 47 | return match (strtolower($permLevel)) { |
| 48 | 'basic' => new BasicPermission($configuration), |
| 49 | 'medium' => new MediumPermission($configuration), |
| 50 | default => throw new InvalidArgumentException(sprintf('Invalid permission level: %s', $permLevel)), |
| 51 | }; |
| 52 | } |
| 53 | } |