Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| OlzTypedEndpoint | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| runtimeSetup | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| checkPermission | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| checkIsStaff | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Api; |
| 4 | |
| 5 | use Olz\Utils\WithUtilsTrait; |
| 6 | use PhpTypeScriptApi\HttpError; |
| 7 | use PhpTypeScriptApi\TypedEndpoint; |
| 8 | |
| 9 | /** |
| 10 | * @template Request |
| 11 | * @template Response |
| 12 | * |
| 13 | * @extends TypedEndpoint<Request, Response> |
| 14 | */ |
| 15 | abstract class OlzTypedEndpoint extends TypedEndpoint { |
| 16 | use WithUtilsTrait; |
| 17 | |
| 18 | public function runtimeSetup(): void { |
| 19 | $this->setLogger($this->log()); |
| 20 | } |
| 21 | |
| 22 | // --- Custom --- |
| 23 | |
| 24 | protected function checkPermission(string $permission): void { |
| 25 | $has_access = $this->authUtils()->hasPermission($permission); |
| 26 | if (!$has_access) { |
| 27 | throw new HttpError(403, "Kein Zugriff!"); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | protected function checkIsStaff(): void { |
| 32 | $has_access = !empty($this->authUtils()->getAuthenticatedRoles()); |
| 33 | if (!$has_access) { |
| 34 | throw new HttpError(403, "Kein Zugriff!"); |
| 35 | } |
| 36 | } |
| 37 | } |