Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
ProcessGet | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
readResponse | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
testProcessData | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 |
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\Process; |
13 | |
14 | class ProcessGet 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 | $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(2)->getValue(); |
26 | $this->testProcessData($args['id'], $args['authKey']); |
27 | |
28 | $message = Response\Message::create($request); |
29 | $message->data = (new Process())->readEntity($args['id'], $args['authKey'], $resolveReferences); |
30 | |
31 | $response = Render::withLastModified($response, time(), '0'); |
32 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); |
33 | return $response; |
34 | } |
35 | |
36 | protected function testProcessData($processId, $authKey) |
37 | { |
38 | $authCheck = (new Process())->readAuthKeyByProcessId($processId); |
39 | if (! $authCheck) { |
40 | throw new Exception\Process\ProcessNotFound(); |
41 | } elseif ($authCheck['authKey'] != $authKey && $authCheck['authName'] != $authKey) { |
42 | throw new Exception\Process\AuthKeyMatchFailed(); |
43 | } |
44 | } |
45 | } |