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