|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Http\Controllers; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Domain\Entities\IStringerEntity; |
|
8
|
|
|
use AbterPhp\Framework\Domain\Entities\IToJsoner; |
|
|
|
|
|
|
9
|
|
|
use Opulence\Http\Responses\Response; |
|
10
|
|
|
use Opulence\Http\Responses\ResponseHeaders; |
|
11
|
|
|
|
|
12
|
|
|
trait ApiResponseTrait |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param IStringerEntity $entity |
|
16
|
|
|
* |
|
17
|
|
|
* @return Response |
|
18
|
|
|
*/ |
|
19
|
|
|
protected function handleGetSuccess(IStringerEntity $entity): Response |
|
20
|
|
|
{ |
|
21
|
|
|
$response = new Response(); |
|
22
|
|
|
$response->setStatusCode(ResponseHeaders::HTTP_OK); |
|
23
|
|
|
$response->setContent($entity->toJSON()); |
|
24
|
|
|
|
|
25
|
|
|
return $response; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param array $entities |
|
30
|
|
|
* @param int $total |
|
31
|
|
|
* |
|
32
|
|
|
* @return Response |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function handleListSuccess(array $entities, int $total): Response |
|
35
|
|
|
{ |
|
36
|
|
|
$data = []; |
|
37
|
|
|
foreach ($entities as $entity) { |
|
38
|
|
|
$data[] = $entity->toJSON(); |
|
39
|
|
|
} |
|
40
|
|
|
$content = sprintf('{"total":%d,"data":[%s]}', $total, implode(',', $data)); |
|
41
|
|
|
|
|
42
|
|
|
$response = new Response(); |
|
43
|
|
|
$response->setStatusCode(ResponseHeaders::HTTP_OK); |
|
44
|
|
|
$response->setContent($content); |
|
45
|
|
|
|
|
46
|
|
|
return $response; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param IStringerEntity $entity |
|
51
|
|
|
* |
|
52
|
|
|
* @return Response |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function handleCreateSuccess(IStringerEntity $entity): Response |
|
55
|
|
|
{ |
|
56
|
|
|
$response = new Response(); |
|
57
|
|
|
$response->setStatusCode(ResponseHeaders::HTTP_CREATED); |
|
58
|
|
|
$response->setContent($entity->toJSON()); |
|
59
|
|
|
|
|
60
|
|
|
return $response; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param IStringerEntity $entity |
|
65
|
|
|
* |
|
66
|
|
|
* @return Response |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function handleUpdateSuccess(IStringerEntity $entity): Response |
|
69
|
|
|
{ |
|
70
|
|
|
$response = new Response(); |
|
71
|
|
|
$response->setStatusCode(ResponseHeaders::HTTP_OK); |
|
72
|
|
|
$response->setContent($entity->toJSON()); |
|
73
|
|
|
|
|
74
|
|
|
return $response; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return Response |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function handleDeleteSuccess(): Response |
|
81
|
|
|
{ |
|
82
|
|
|
$response = new Response(); |
|
83
|
|
|
$response->setStatusCode(ResponseHeaders::HTTP_NO_CONTENT); |
|
84
|
|
|
|
|
85
|
|
|
return $response; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return Response |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function handleNotFound(): Response |
|
92
|
|
|
{ |
|
93
|
|
|
$response = new Response(); |
|
94
|
|
|
$response->setStatusCode(ResponseHeaders::HTTP_NOT_FOUND); |
|
95
|
|
|
|
|
96
|
|
|
return $response; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @return Response |
|
101
|
|
|
*/ |
|
102
|
|
|
protected function handleNotImplemented(): Response |
|
103
|
|
|
{ |
|
104
|
|
|
$response = new Response(); |
|
105
|
|
|
$response->setStatusCode(ResponseHeaders::HTTP_NOT_IMPLEMENTED); |
|
106
|
|
|
|
|
107
|
|
|
return $response; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths