1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ps2alerts\Api\Controller\Endpoint; |
4
|
|
|
|
5
|
|
|
use League\Fractal\Manager; |
6
|
|
|
use Ps2alerts\Api\Controller\Endpoint\AbstractEndpointController; |
7
|
|
|
use Ps2alerts\Api\Repository\AlertRepository; |
8
|
|
|
use Ps2alerts\Api\Transformer\AlertTransformer; |
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
11
|
|
|
|
12
|
|
|
class AlertEndpointController extends AbstractEndpointController |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Construct |
16
|
|
|
* |
17
|
|
|
* @param Ps2alerts\Api\Repository\AlertRepository $repository |
18
|
|
|
* @param Ps2alerts\Api\Transformer\AlertTransformer $transformer |
19
|
|
|
* @param League\Fractal\Manager $fractal |
20
|
|
|
*/ |
21
|
|
|
public function __construct( |
22
|
|
|
AlertRepository $repository, |
23
|
|
|
AlertTransformer $transformer, |
24
|
|
|
Manager $fractal |
25
|
|
|
) { |
26
|
|
|
$this->repository = $repository; |
27
|
|
|
$this->transformer = $transformer; |
28
|
|
|
$this->fractal = $fractal; |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Returns a single alert's information |
33
|
|
|
* |
34
|
|
|
* @see AbstractEndpointController::respondWithItem |
35
|
|
|
* |
36
|
|
|
* @param Symfony\Component\HttpFoundation\Request $request |
37
|
|
|
* @param Symfony\Component\HttpFoundation\Response $response |
38
|
|
|
* @param array $args |
39
|
|
|
* |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
View Code Duplication |
public function getSingle(Request $request, Response $response, array $args) |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$alert = $this->repository->readSingleById($args['id']); |
45
|
|
|
|
46
|
|
|
if (empty($alert)) { |
47
|
|
|
return $this->errorEmpty($response); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $this->respond('item', $alert, $this->transformer, $request, $response); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
View Code Duplication |
public function getActives(Request $request, Response $response) |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$actives = $this->repository->readAllByField('InProgress', 1); |
56
|
|
|
|
57
|
|
|
if (empty($actives)) { |
58
|
|
|
return $this->errorEmpty($response); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $this->respond('collection', $actives, $this->transformer, $request, $response); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..