Lines
100.00%
19 / 19
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ApikeyUpdate | 100.00% | 19 / 19 | 100.00% | 1 / 1 | 6 | 100.00% | 1 / 1 | |||
| readResponse | 100.00% | 19 / 19 | 100.00% | 1 / 1 | 6 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package ZMS API | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsbackend\Apikey\Api; | |
| 9 | ||
| 10 | use BO\Slim\Render; | |
| 11 | use BO\Mellon\Validator; | |
| 12 | use BO\Zmsbackend\Apikey\Service\Apikey as Query; | |
| 13 | ||
| 14 | class ApikeyUpdate extends \BO\Zmsbackend\Api\BaseController | |
| 15 | { | |
| 16 | /** | |
| 17 | * @SuppressWarnings(Param) | |
| 18 | * @return \Psr\Http\Message\ResponseInterface | |
| 19 | */ | |
| 20 | #[\Override] | |
| 21 | public function readResponse( | |
| 22 | \Psr\Http\Message\RequestInterface $request, | |
| 23 | \Psr\Http\Message\ResponseInterface $response, | |
| 24 | array $args | |
| 25 | ) { | |
| 26 | $validator = $request->getAttribute('validator'); | |
| 27 | $clientKey = $validator->getParameter('clientkey')->isString()->getValue(); | |
| 28 | $input = Validator::input()->isJson()->assertValid()->getValue(); | |
| 29 | $entity = new \BO\Zmsentities\Apikey($input); | |
| 30 | ||
| 31 | \BO\Zmsbackend\Connection\Select::getWriteConnection(); | |
| 32 | $apiKey = (new Query())->readEntity($entity->key); | |
| 33 | if ($clientKey) { | |
| 34 | $apiClient = (new \BO\Zmsbackend\Apikey\Service\Apiclient())->readEntity($clientKey); | |
| 35 | if (!$apiClient || !isset($apiClient->accesslevel) || $apiClient->accesslevel == 'blocked') { | |
| 36 | throw new \BO\Zmsbackend\Process\Exception\ApiclientInvalid(); | |
| 37 | } | |
| 38 | $apiKey->setApiclient($apiClient); | |
| 39 | } | |
| 40 | if (! $apiKey->hasId()) { | |
| 41 | $entity = (new Query())->writeEntity($entity); | |
| 42 | } else { | |
| 43 | $entity = (new Query())->updateEntity($entity->key, $entity); | |
| 44 | } | |
| 45 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 46 | $message->data = $entity; | |
| 47 | ||
| 48 | $response = Render::withLastModified($response, time(), '0'); | |
| 49 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 50 | return $response; | |
| 51 | } | |
| 52 | } |