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 | 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 | */ |
||
54 | public function createObject(BaseInterface $object, string $reqRoute) :BaseInterface |
||
61 | |||
62 | /** |
||
63 | * @param BaseInterface $object |
||
64 | * @param int $id |
||
65 | * @param string $reqRoute |
||
66 | * |
||
67 | * @return BaseInterface |
||
68 | * @throws EmptyResponseException |
||
69 | * @throws NotFoundException |
||
70 | */ |
||
71 | public function getObjectById(BaseInterface $object, int $id, string $reqRoute) :BaseInterface |
||
83 | |||
84 | /** |
||
85 | * @param BaseInterface $object |
||
86 | * @param array $searchTerm |
||
87 | * @param string $reqRoute |
||
88 | * |
||
89 | * @return BaseInterface[] |
||
90 | * @throws ApiException |
||
91 | * @throws InvalidParameterException |
||
92 | */ |
||
93 | public function findObjectBy(BaseInterface $object, array $searchTerm, string $reqRoute) :array |
||
114 | |||
115 | /** |
||
116 | * @param BaseInterface $object |
||
117 | * @param string $reqRoute |
||
118 | * |
||
119 | * @return BaseInterface |
||
120 | * @throws ApiException |
||
121 | * @throws EmptyResponseException |
||
122 | */ |
||
123 | public function restoreObject(BaseInterface $object, string $reqRoute) :BaseInterface |
||
127 | |||
128 | /** |
||
129 | * @param BaseInterface $object |
||
130 | * @param string $reqRoute |
||
131 | * |
||
132 | * @return BaseInterface |
||
133 | * @throws ApiException |
||
134 | * @throws EmptyResponseException |
||
135 | */ |
||
136 | public function archiveObject(BaseInterface $object, string $reqRoute) :BaseInterface |
||
140 | |||
141 | /** |
||
142 | * @param BaseInterface $object |
||
143 | * @param string $reqRoute |
||
144 | * |
||
145 | * @return BaseInterface |
||
146 | * @throws ApiException |
||
147 | * @throws EmptyResponseException |
||
148 | */ |
||
149 | public function updateObject(BaseInterface $object, string $reqRoute) :BaseInterface |
||
153 | |||
154 | /** |
||
155 | * @param BaseInterface $object |
||
156 | * @param string $reqRoute |
||
157 | * @param string|null $action |
||
158 | * |
||
159 | * @return BaseInterface |
||
160 | * @throws ApiException |
||
161 | * @throws EmptyResponseException |
||
162 | */ |
||
163 | private function update(BaseInterface $object, $reqRoute, ?string $action = null) :BaseInterface |
||
180 | |||
181 | /** |
||
182 | * @param BaseInterface $object |
||
183 | * @param string $reqRoute |
||
184 | * |
||
185 | * @return BaseInterface |
||
186 | * @throws ApiException |
||
187 | * @throws EmptyResponseException |
||
188 | */ |
||
189 | public function deleteObject(BaseInterface $object, string $reqRoute) :BaseInterface |
||
198 | |||
199 | /** |
||
200 | * Retrieves all objects. |
||
201 | * Default page size on server side is 15! |
||
202 | * @param BaseInterface $object |
||
203 | * @param string $reqRoute |
||
204 | * @param int $page |
||
205 | * @param int $pageSize |
||
206 | * |
||
207 | * @return BaseInterface[] |
||
208 | * @throws ApiException |
||
209 | * @throws EmptyResponseException |
||
210 | */ |
||
211 | public function getAllObjects(BaseInterface $object, string $reqRoute, int $page = 1, int $pageSize = 0) :array |
||
225 | |||
226 | /** |
||
227 | * @param int $id |
||
228 | * |
||
229 | * @return array |
||
230 | * @throws ApiException |
||
231 | * @throws EmptyResponseException |
||
232 | */ |
||
233 | public function downloadFile(int $id) :array |
||
241 | |||
242 | /** |
||
243 | * @param array $data |
||
244 | * @param BaseInterface $object |
||
245 | * |
||
246 | * @return BaseInterface |
||
247 | */ |
||
248 | private function hydrateObject(array $data, BaseInterface $object) :BaseInterface |
||
252 | } |
||
253 |