Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @file |
| 5 | * Login action: logout session and notify connected instances. |
| 6 | */ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | require_once __DIR__.'/../../Legacy/common/logout.php'; |
| 11 | |
| 12 | /** |
| 13 | * Action callable: logout session (GET session). |
| 14 | * |
| 15 | * Releases session and notifies connected instances via legacy logout_session_and_notify. |
| 16 | * |
| 17 | * @param string $body Request body (unused). |
| 18 | * @param array<string, mixed> $query Query params: session. |
| 19 | * @param \ConxHelper $conx Connection helper (from LoginService; uses ->global for central DB). |
| 20 | * @param \Psr\Log\LoggerInterface $logger Logger (from LoggerFactory). |
| 21 | * @param \UppServices\SessionService $sessionService Session service (unused; logout uses legacy logout_session_and_notify). |
| 22 | * @return array{output: string, contentType: string} JSON output and content type. |
| 23 | */ |
| 24 | return function (string $body, array $query, \ConxHelper $conx, \Psr\Log\LoggerInterface $logger, \UppServices\SessionService $sessionService): array { |
| 25 | $retval = ApplicationError::Success; |
| 26 | $session = $query['session'] ?? null; |
| 27 | if (!$session) { |
| 28 | $logger->error("No session provided on URL. Operation cancelled."); |
| 29 | $retval = ApplicationError::Parameters; |
| 30 | } |
| 31 | |
| 32 | $result = ["errorcode" => $retval]; |
| 33 | if (success($retval)) { |
| 34 | $when = $conx->global->now(); |
| 35 | $retval = logout_session_and_notify($conx->global, $when, $session); |
| 36 | $result = ["errorcode" => $retval]; |
| 37 | } |
| 38 | |
| 39 | $logger->debug("Logout session: [".$session."] completed with errorcode: ".$retval); |
| 40 | $output = json_encode($result); |
| 41 | return ['output' => $output, 'contentType' => 'application/json; charset=utf-8']; |
| 42 | }; |