1 | <?php |
||
67 | class RemoteStreamService extends NC21Signature { |
||
68 | |||
69 | |||
70 | use TNC21Deserialize; |
||
71 | use TNC21LocalSignatory; |
||
72 | use TStringTools; |
||
73 | use TNC21WellKnown; |
||
74 | |||
75 | |||
76 | const UPDATE_DATA = 'data'; |
||
77 | const UPDATE_INSTANCE = 'instance'; |
||
78 | const UPDATE_HREF = 'href'; |
||
79 | |||
80 | |||
81 | /** @var IURLGenerator */ |
||
82 | private $urlGenerator; |
||
83 | |||
84 | /** @var RemoteRequest */ |
||
85 | private $remoteRequest; |
||
86 | |||
87 | /** @var ConfigService */ |
||
88 | private $configService; |
||
89 | |||
90 | |||
91 | /** |
||
92 | * RemoteStreamService constructor. |
||
93 | * |
||
94 | * @param IURLGenerator $urlGenerator |
||
95 | * @param RemoteRequest $remoteRequest |
||
96 | * @param ConfigService $configService |
||
97 | */ |
||
98 | public function __construct( |
||
107 | |||
108 | |||
109 | /** |
||
110 | * Returns the Signatory model for the Circles app. |
||
111 | * Can be signed with a confirmKey. |
||
112 | * |
||
113 | * @param bool $generate |
||
114 | * @param string $confirmKey |
||
115 | * |
||
116 | * @return RemoteInstance |
||
117 | * @throws SignatoryException |
||
118 | */ |
||
119 | public function getAppSignatory(bool $generate = true, string $confirmKey = ''): RemoteInstance { |
||
161 | |||
162 | |||
163 | /** |
||
164 | * Reset the Signatory (and the Identity) for the Circles app. |
||
165 | */ |
||
166 | public function resetAppSignatory(): void { |
||
174 | |||
175 | |||
176 | /** |
||
177 | * shortcut to requestRemoteInstance that return result if available, or exception. |
||
178 | * |
||
179 | * @param string $instance |
||
180 | * @param string $item |
||
181 | * @param int $type |
||
182 | * @param JsonSerializable|null $object |
||
183 | * @param array $params |
||
184 | * |
||
185 | * @return array |
||
186 | * @throws RemoteNotFoundException |
||
187 | * @throws RemoteResourceNotFoundException |
||
188 | * @throws RequestNetworkException |
||
189 | * @throws SignatoryException |
||
190 | * @throws UnknownRemoteException |
||
191 | * @throws RemoteInstanceException |
||
192 | */ |
||
193 | public function resultRequestRemoteInstance( |
||
213 | |||
214 | /** |
||
215 | * Send a request to a remote instance, based on: |
||
216 | * - instance: address as saved in database, |
||
217 | * - item: the item to request (incoming, event, ...) |
||
218 | * - type: GET, POST |
||
219 | * - data: Serializable to be send if needed |
||
220 | * |
||
221 | * @param string $instance |
||
222 | * @param string $item |
||
223 | * @param int $type |
||
224 | * @param JsonSerializable|null $object |
||
225 | * @param array $params |
||
226 | * |
||
227 | * @return NC21SignedRequest |
||
228 | * @throws RemoteNotFoundException |
||
229 | * @throws RemoteResourceNotFoundException |
||
230 | * @throws RequestNetworkException |
||
231 | * @throws SignatoryException |
||
232 | * @throws UnknownRemoteException |
||
233 | */ |
||
234 | public function requestRemoteInstance( |
||
267 | |||
268 | |||
269 | /** |
||
270 | * get the value of an entry from the Signatory of the RemoteInstance. |
||
271 | * |
||
272 | * @param string $instance |
||
273 | * @param string $item |
||
274 | * @param array $params |
||
275 | * |
||
276 | * @return string |
||
277 | * @throws RemoteNotFoundException |
||
278 | * @throws RemoteResourceNotFoundException |
||
279 | * @throws UnknownRemoteException |
||
280 | */ |
||
281 | private function getRemoteInstanceEntry(string $instance, string $item, array $params = []): string { |
||
291 | |||
292 | |||
293 | /** |
||
294 | * get RemoteInstance with confirmed and known identity from database. |
||
295 | * |
||
296 | * @param string $instance |
||
297 | * |
||
298 | * @return RemoteInstance |
||
299 | * @throws RemoteNotFoundException |
||
300 | * @throws UnknownRemoteException |
||
301 | */ |
||
302 | public function getCachedRemoteInstance(string $instance): RemoteInstance { |
||
310 | |||
311 | |||
312 | /** |
||
313 | * Add a remote instance, based on the address |
||
314 | * |
||
315 | * @param string $instance |
||
316 | * |
||
317 | * @return RemoteInstance |
||
318 | * @throws RequestNetworkException |
||
319 | * @throws SignatoryException |
||
320 | * @throws SignatureException |
||
321 | * @throws WellKnownLinkNotFoundException |
||
322 | */ |
||
323 | public function retrieveRemoteInstance(string $instance): RemoteInstance { |
||
331 | |||
332 | |||
333 | /** |
||
334 | * retrieve Signatory. |
||
335 | * |
||
336 | * @param string $keyId |
||
337 | * @param bool $refresh |
||
338 | * |
||
339 | * @return RemoteInstance |
||
340 | * @throws SignatoryException |
||
341 | * @throws SignatureException |
||
342 | */ |
||
343 | public function retrieveSignatory(string $keyId, bool $refresh = true): RemoteInstance { |
||
362 | |||
363 | |||
364 | /** |
||
365 | * Add a remote instance, based on the address |
||
366 | * |
||
367 | * @param string $instance |
||
368 | * @param string $type |
||
369 | * @param bool $overwrite |
||
370 | * |
||
371 | * @throws RequestNetworkException |
||
372 | * @throws SignatoryException |
||
373 | * @throws SignatureException |
||
374 | * @throws WellKnownLinkNotFoundException |
||
375 | * @throws RemoteAlreadyExistsException |
||
376 | * @throws RemoteUidException |
||
377 | */ |
||
378 | public function addRemoteInstance( |
||
400 | |||
401 | |||
402 | /** |
||
403 | * Confirm the Auth of a RemoteInstance, based on the result from a request |
||
404 | * |
||
405 | * @param RemoteInstance $remote |
||
406 | * @param string $auth |
||
407 | * |
||
408 | * @throws SignatureException |
||
409 | */ |
||
410 | private function confirmAuth(RemoteInstance $remote, string $auth): void { |
||
426 | |||
427 | |||
428 | /** |
||
429 | * TODO: confirm if method is really needed |
||
430 | * |
||
431 | * @param RemoteInstance $remote |
||
432 | * @param RemoteInstance|null $stored |
||
433 | * |
||
434 | * @throws RemoteNotFoundException |
||
435 | * @throws RemoteUidException |
||
436 | */ |
||
437 | public function confirmValidRemote(RemoteInstance $remote, ?RemoteInstance &$stored = null): void { |
||
452 | |||
453 | |||
454 | /** |
||
455 | * TODO: check if this method is not useless |
||
456 | * |
||
457 | * @param RemoteInstance $remote |
||
458 | * @param string $update |
||
459 | * |
||
460 | * @throws RemoteUidException |
||
461 | */ |
||
462 | public function update(RemoteInstance $remote, string $update = self::UPDATE_DATA): void { |
||
477 | |||
478 | } |
||
479 | |||
480 |