Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
76.92% |
20 / 26 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @file |
| 5 | * Guest check action: verify an existing guest session. |
| 6 | */ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | /** |
| 11 | * Action callable: check guest session (GET device + session). |
| 12 | * |
| 13 | * Calls SessionService::checkAccess and returns qrscan objid on success. |
| 14 | * |
| 15 | * @param string $body Unused (GET); kept for action signature parity. |
| 16 | * @param array<string, mixed> $query Query params: device, session. |
| 17 | * @param \ConxHelper $conx Connection helper (central DB via ->global). |
| 18 | * @param \Psr\Log\LoggerInterface $logger Logger (from LoggerFactory). |
| 19 | * @param \UppServices\SessionService $sessionService Session service for check. |
| 20 | * @return array{output: string, contentType: string} JSON output and content type. |
| 21 | */ |
| 22 | return function (string $body, array $query, \ConxHelper $conx, \Psr\Log\LoggerInterface $logger, \UppServices\SessionService $sessionService): array { |
| 23 | $retval = ApplicationError::Success; |
| 24 | $qrscanid = null; |
| 25 | |
| 26 | $deviceid = $query['device'] ?? null; |
| 27 | if (!$deviceid) { |
| 28 | $logger->error("Missing 'device' parameter in url request"); |
| 29 | $retval = ApplicationError::Parameters; |
| 30 | } |
| 31 | |
| 32 | if (success($retval)) { |
| 33 | $sessionid = $query['session'] ?? null; |
| 34 | if (!$sessionid) { |
| 35 | $logger->error("Missing 'session' parameter in url request"); |
| 36 | $retval = ApplicationError::Parameters; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | if (success($retval)) { |
| 41 | $qrscanid = null; |
| 42 | $retval = $sessionService->checkAccess($conx, (string) $sessionid, (string) $deviceid, $qrscanid); |
| 43 | } |
| 44 | |
| 45 | if (success($retval)) { |
| 46 | $result = [ |
| 47 | 'errorcode' => $retval, |
| 48 | 'qrscan' => $qrscanid, |
| 49 | ]; |
| 50 | } |
| 51 | else { |
| 52 | $result = [ |
| 53 | 'errorcode' => $retval, |
| 54 | ]; |
| 55 | } |
| 56 | |
| 57 | $output = json_encode($result); |
| 58 | return ['output' => $output, 'contentType' => 'application/json; charset=utf-8']; |
| 59 | }; |