Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
TicketbaiController
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 respond
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 authorize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 derived
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 async
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 audit
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5use Psr\Http\Message\ResponseInterface as Response;
6use Psr\Http\Message\ServerRequestInterface as Request;
7use UppServices\TicketbaiService;
8
9/**
10 * Slim controller for TicketBAI signing material endpoints.
11 */
12class TicketbaiController
13{
14    private readonly TicketbaiService $ticketbaiService;
15
16    public function __construct(TicketbaiService $ticketbaiService)
17    {
18        $this->ticketbaiService = $ticketbaiService;
19    }
20
21    private function respond(Response $response, array $result): Response
22    {
23        $response->getBody()->write($result['output']);
24        return $response->withHeader('Content-Type', $result['contentType']);
25    }
26
27    /** GET /ticketbai/authorize - get encrypted PKCS#8 + certificate material. */
28    public function authorize(Request $request, Response $response): Response
29    {
30        return $this->respond($response, $this->ticketbaiService->authorize($request->getQueryParams()));
31    }
32
33    /** GET /ticketbai/derived - get server PIN used to derive decryption key. */
34    public function derived(Request $request, Response $response): Response
35    {
36        return $this->respond($response, $this->ticketbaiService->derived($request->getQueryParams()));
37    }
38
39    /** POST /ticketbai/async - schedule async TicketBAI update processing. */
40    public function async(Request $request, Response $response): Response
41    {
42        $rawBody = (string) $request->getBody();
43        return $this->respond($response, $this->ticketbaiService->async($rawBody));
44    }
45
46    /** GET /ticketbai/audit — retry pending TicketBAI for a closed audit period. */
47    public function audit(Request $request, Response $response): Response
48    {
49        $out = $this->ticketbaiService->audit($request->getQueryParams());
50        $response->getBody()->write(json_encode($out));
51
52        return $response->withHeader('Content-Type', 'application/json');
53    }
54}
55