Lines
0.00%
0 / 15
Functions and Methods
0.00%
0 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| AppointmentUrlMiddleware | 0.00% | 0 / 15 | 0.00% | 0 / 2 | 42 | 0.00% | 0 / 1 | |||
| process | 0.00% | 0 / 2 | 0.00% | 0 / 1 | 2 | |||||
| readAppointmentUrl | 0.00% | 0 / 13 | 0.00% | 0 / 1 | 30 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsclient; | |
| 4 | ||
| 5 | use BO\Zmsentities\Config; | |
| 6 | use Psr\Http\Message\ResponseInterface; | |
| 7 | use Psr\Http\Message\ServerRequestInterface; | |
| 8 | use Psr\Http\Server\MiddlewareInterface; | |
| 9 | use Psr\Http\Server\RequestHandlerInterface; | |
| 10 | ||
| 11 | class AppointmentUrlMiddleware implements MiddlewareInterface | |
| 12 | { | |
| 13 | #[\Override] | |
| 14 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | |
| 15 | { | |
| 16 | \App::$templatedefaults['urlAppointments'] = self::readAppointmentUrl(); | |
| 17 | ||
| 18 | return $handler->handle($request); | |
| 19 | } | |
| 20 | ||
| 21 | public static function readAppointmentUrl(): string | |
| 22 | { | |
| 23 | try { | |
| 24 | $token = defined('App::CONFIG_SECURE_TOKEN') ? \App::CONFIG_SECURE_TOKEN : null; | |
| 25 | $entity = \App::$http->readGetResult('/config/', [], $token)->getEntity(); | |
| 26 | } catch (\Throwable $exception) { | |
| 27 | \App::$log->error('Failed to read the appointment URL', [ | |
| 28 | 'error' => $exception->getMessage(), | |
| 29 | ]); | |
| 30 | return ''; | |
| 31 | } | |
| 32 | ||
| 33 | if (!$entity instanceof Config) { | |
| 34 | return ''; | |
| 35 | } | |
| 36 | ||
| 37 | $url = $entity->getPreference('appointments', 'urlAppointments'); | |
| 38 | if (!is_string($url)) { | |
| 39 | return ''; | |
| 40 | } | |
| 41 | ||
| 42 | return trim($url); | |
| 43 | } | |
| 44 | } |