Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| 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\Zmsapi; |
| 9 | |
| 10 | use BO\Slim\Render; |
| 11 | use BO\Mellon\Validator; |
| 12 | use BO\Zmsdb\Apikey as Query; |
| 13 | |
| 14 | class ApikeyUpdate extends BaseController |
| 15 | { |
| 16 | /** |
| 17 | * @SuppressWarnings(Param) |
| 18 | * @return String |
| 19 | */ |
| 20 | public function readResponse( |
| 21 | \Psr\Http\Message\RequestInterface $request, |
| 22 | \Psr\Http\Message\ResponseInterface $response, |
| 23 | array $args |
| 24 | ) { |
| 25 | $validator = $request->getAttribute('validator'); |
| 26 | $clientKey = $validator->getParameter('clientkey')->isString()->getValue(); |
| 27 | $input = Validator::input()->isJson()->assertValid()->getValue(); |
| 28 | $entity = new \BO\Zmsentities\Apikey($input); |
| 29 | |
| 30 | \BO\Zmsdb\Connection\Select::getWriteConnection(); |
| 31 | $apiKey = (new Query())->readEntity($entity->key); |
| 32 | if ($clientKey) { |
| 33 | $apiClient = (new \BO\Zmsdb\Apiclient())->readEntity($clientKey); |
| 34 | if (!$apiClient || !isset($apiClient->accesslevel) || $apiClient->accesslevel == 'blocked') { |
| 35 | throw new Exception\Process\ApiclientInvalid(); |
| 36 | } |
| 37 | $apiKey->setApiclient($apiClient); |
| 38 | } |
| 39 | if (! $apiKey->hasId()) { |
| 40 | $entity = (new Query())->writeEntity($entity); |
| 41 | } else { |
| 42 | $entity = (new Query())->updateEntity($entity->key, $entity); |
| 43 | } |
| 44 | $message = Response\Message::create($request); |
| 45 | $message->data = $entity; |
| 46 | |
| 47 | $response = Render::withLastModified($response, time(), '0'); |
| 48 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); |
| 49 | return $response; |
| 50 | } |
| 51 | } |