Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.00% |
6 / 8 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ServerInformationEndpoint | |
75.00% |
6 / 8 |
|
0.00% |
0 / 1 |
2.06 | |
0.00% |
0 / 1 |
| handle | |
75.00% |
6 / 8 |
|
0.00% |
0 / 1 |
2.06 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace LambdaTwelve\OneRecord\Server\Endpoint; |
| 6 | |
| 7 | use LambdaTwelve\OneRecord\Api\ServerInformation; |
| 8 | use LambdaTwelve\OneRecord\Rdf\Iri; |
| 9 | use LambdaTwelve\OneRecord\Server\Http\Negotiated; |
| 10 | use LambdaTwelve\OneRecord\Server\Http\Responder; |
| 11 | use LambdaTwelve\OneRecord\Server\Spi\Agent; |
| 12 | use LambdaTwelve\OneRecord\Vocabulary\Generated\Api; |
| 13 | use Psr\Http\Message\ResponseInterface; |
| 14 | use Psr\Http\Message\ServerRequestInterface; |
| 15 | |
| 16 | /** |
| 17 | * GET /: api:ServerInformation. Authentication only; no access control, as the |
| 18 | * spec's security table says. |
| 19 | */ |
| 20 | final class ServerInformationEndpoint extends AbstractEndpoint |
| 21 | { |
| 22 | public function handle(ServerRequestInterface $request, Agent $agent, Negotiated $negotiated, array $parameters): ResponseInterface |
| 23 | { |
| 24 | $config = $this->services->config; |
| 25 | $holderType = $config->dataHolderType; |
| 26 | if ($holderType === null) { |
| 27 | $holder = $this->services->objects->latest($config->dataHolder); |
| 28 | $holderType = $holder?->object->mostSpecificType($this->services->vocabulary); |
| 29 | } |
| 30 | $information = ServerInformation::for(new Iri($config->endpoint()), $config->dataHolder, $config->apiVersions, $config->dataModelVersions, $config->languages, $holderType); |
| 31 | // Server information changes only with configuration; "now" is the honest Last-Modified without a deployment timestamp. |
| 32 | $headers = ['Last-Modified' => Responder::httpDate($this->services->clock->now())]; |
| 33 | |
| 34 | return $this->services->responder->jsonLd(200, $information->toJsonLd(), $negotiated, Api::ServerInformation, $headers, self::isHead($request)); |
| 35 | } |
| 36 | } |