Lines
100.00%
14 / 14
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ConfigUpdate | 100.00% | 14 / 14 | 100.00% | 1 / 1 | 3 | 100.00% | 1 / 1 | |||
| readResponse | 100.00% | 14 / 14 | 100.00% | 1 / 1 | 3 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package ZMS API | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsbackend\Config\Api; | |
| 9 | ||
| 10 | use BO\Slim\Render; | |
| 11 | use BO\Mellon\Validator; | |
| 12 | use BO\Zmsbackend\Config\Service\Config as Query; | |
| 13 | use BO\Zmsbackend\Helper\User; | |
| 14 | ||
| 15 | class ConfigUpdate extends \BO\Zmsbackend\Api\BaseController | |
| 16 | { | |
| 17 | /** | |
| 18 | * @SuppressWarnings(Param) | |
| 19 | * @return \Psr\Http\Message\ResponseInterface | |
| 20 | */ | |
| 21 | #[\Override] | |
| 22 | public function readResponse( | |
| 23 | \Psr\Http\Message\RequestInterface $request, | |
| 24 | \Psr\Http\Message\ResponseInterface $response, | |
| 25 | array $args | |
| 26 | ) { | |
| 27 | try { | |
| 28 | (new \BO\Zmsbackend\Helper\User($request))->checkPermissions('config'); | |
| 29 | } catch (\Exception $exception) { | |
| 30 | $token = $request->getHeader('X-Token'); | |
| 31 | if (\App::SECURE_TOKEN != current($token)) { | |
| 32 | throw new \BO\Zmsbackend\Config\Exception\ConfigAuthentificationFailed(); | |
| 33 | } | |
| 34 | } | |
| 35 | $input = Validator::input()->isJson()->assertValid()->getValue(); | |
| 36 | $entity = new \BO\Zmsentities\Config($input); | |
| 37 | $entity->testValid(); | |
| 38 | $entity = (new Query())->updateEntity($entity); | |
| 39 | ||
| 40 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 41 | $message->data = $entity; | |
| 42 | ||
| 43 | $response = Render::withLastModified($response, time(), '0'); | |
| 44 | $response = Render::withJson($response, $message, $message->getStatuscode()); | |
| 45 | return $response; | |
| 46 | } | |
| 47 | } |