1 | <?php |
||
21 | final class ObjectService implements ObjectServiceInterface |
||
22 | { |
||
23 | const ACTION_RESTORE = 'restore'; |
||
24 | const ACTION_ARCHIVE = 'archive'; |
||
25 | const ROUTE_DOWNLOAD = '/download'; |
||
26 | |||
27 | /** @var RequestServiceInterface */ |
||
28 | protected $requestService; |
||
29 | /** @var HydratorInterface */ |
||
30 | protected $hydrator; |
||
31 | /** @var BaseInterface */ |
||
32 | protected $objectType; |
||
33 | |||
34 | /** |
||
35 | * BaseManager constructor. |
||
36 | * |
||
37 | * @param RequestServiceInterface $requestService |
||
38 | * @param HydratorInterface $hydrator |
||
39 | */ |
||
40 | 17 | public function __construct(RequestServiceInterface $requestService, HydratorInterface $hydrator) |
|
45 | |||
46 | /** |
||
47 | * @param BaseInterface $object |
||
48 | * @param $reqRoute |
||
49 | * |
||
50 | * @return BaseInterface |
||
51 | * @throws ApiException |
||
52 | * @throws EmptyResponseException |
||
53 | * @throws InvalidResultException |
||
54 | */ |
||
55 | 1 | public function createObject(BaseInterface $object, string $reqRoute) :BaseInterface |
|
62 | |||
63 | /** |
||
64 | * @param BaseInterface $object |
||
65 | * @param int $id |
||
66 | * @param string $reqRoute |
||
67 | * |
||
68 | * @return BaseInterface |
||
69 | * @throws EmptyResponseException |
||
70 | * @throws NotFoundException |
||
71 | * @throws InvalidResultException |
||
72 | */ |
||
73 | 2 | public function getObjectById(BaseInterface $object, int $id, string $reqRoute) :BaseInterface |
|
85 | |||
86 | /** |
||
87 | * @param BaseInterface $object |
||
88 | * @param array $searchTerm |
||
89 | * @param string $reqRoute |
||
90 | * |
||
91 | * @return BaseInterface[] |
||
92 | * @throws ApiException |
||
93 | * @throws InvalidParameterException |
||
94 | * @throws InvalidResultException |
||
95 | */ |
||
96 | 5 | public function findObjectBy(BaseInterface $object, array $searchTerm, string $reqRoute) :array |
|
117 | |||
118 | /** |
||
119 | * @param BaseInterface $object |
||
120 | * @param string $reqRoute |
||
121 | * |
||
122 | * @return BaseInterface |
||
123 | * @throws ApiException |
||
124 | * @throws EmptyResponseException |
||
125 | * @throws InvalidResultException |
||
126 | */ |
||
127 | 1 | public function restoreObject(BaseInterface $object, string $reqRoute) :BaseInterface |
|
131 | |||
132 | /** |
||
133 | * @param BaseInterface $object |
||
134 | * @param string $reqRoute |
||
135 | * |
||
136 | * @return BaseInterface |
||
137 | * @throws ApiException |
||
138 | * @throws EmptyResponseException |
||
139 | * @throws InvalidResultException |
||
140 | */ |
||
141 | 1 | public function archiveObject(BaseInterface $object, string $reqRoute) :BaseInterface |
|
145 | |||
146 | /** |
||
147 | * @param BaseInterface $object |
||
148 | * @param string $reqRoute |
||
149 | * |
||
150 | * @return BaseInterface |
||
151 | * @throws ApiException |
||
152 | * @throws EmptyResponseException |
||
153 | * @throws InvalidResultException |
||
154 | */ |
||
155 | 1 | public function updateObject(BaseInterface $object, string $reqRoute) :BaseInterface |
|
159 | |||
160 | /** |
||
161 | * @param BaseInterface $object |
||
162 | * @param string $reqRoute |
||
163 | * @param string|null $action |
||
164 | * |
||
165 | * @return BaseInterface |
||
166 | * @throws ApiException |
||
167 | * @throws EmptyResponseException |
||
168 | * @throws InvalidResultException |
||
169 | */ |
||
170 | 3 | private function update(BaseInterface $object, $reqRoute, ?string $action = null) :BaseInterface |
|
187 | |||
188 | /** |
||
189 | * @param BaseInterface $object |
||
190 | * @param string $reqRoute |
||
191 | * |
||
192 | * @return BaseInterface |
||
193 | * @throws ApiException |
||
194 | * @throws EmptyResponseException |
||
195 | * @throws InvalidResultException |
||
196 | */ |
||
197 | 1 | public function deleteObject(BaseInterface $object, string $reqRoute) :BaseInterface |
|
206 | |||
207 | /** |
||
208 | * Retrieves all objects. |
||
209 | * Default page size on server side is 15! |
||
210 | * @param BaseInterface $object |
||
211 | * @param string $reqRoute |
||
212 | * @param int $page |
||
213 | * @param int $pageSize |
||
214 | * |
||
215 | * @return BaseInterface[] |
||
216 | * @throws ApiException |
||
217 | * @throws EmptyResponseException |
||
218 | * @throws InvalidResultException |
||
219 | */ |
||
220 | 2 | public function getAllObjects(BaseInterface $object, string $reqRoute, int $page = 1, int $pageSize = 0) :array |
|
234 | |||
235 | /** |
||
236 | * @param int $id |
||
237 | * |
||
238 | * @return array |
||
239 | * @throws ApiException |
||
240 | * @throws EmptyResponseException |
||
241 | */ |
||
242 | 1 | public function downloadFile(int $id) :array |
|
250 | |||
251 | /** |
||
252 | * @param array $data |
||
253 | * @param BaseInterface $object |
||
254 | * |
||
255 | * @return BaseInterface |
||
256 | * @throws InvalidResultException |
||
257 | */ |
||
258 | 8 | private function hydrateObject(array $data, BaseInterface $object) :BaseInterface |
|
266 | } |
||
267 |