1 | <?php |
||
74 | class CircleService { |
||
75 | |||
76 | |||
77 | use TArrayTools; |
||
78 | use TStringTools; |
||
79 | use TNC22Logger; |
||
80 | |||
81 | |||
82 | /** @var CircleRequest */ |
||
83 | private $circleRequest; |
||
84 | |||
85 | /** @var MemberRequest */ |
||
86 | private $memberRequest; |
||
87 | |||
88 | /** @var RemoteStreamService */ |
||
89 | private $remoteStreamService; |
||
90 | |||
91 | /** @var FederatedUserService */ |
||
92 | private $federatedUserService; |
||
93 | |||
94 | /** @var FederatedEventService */ |
||
95 | private $federatedEventService; |
||
96 | |||
97 | /** @var MemberService */ |
||
98 | private $memberService; |
||
99 | |||
100 | /** @var ConfigService */ |
||
101 | private $configService; |
||
102 | |||
103 | |||
104 | /** |
||
105 | * CircleService constructor. |
||
106 | * |
||
107 | * @param CircleRequest $circleRequest |
||
108 | * @param MemberRequest $memberRequest |
||
109 | * @param RemoteStreamService $remoteStreamService |
||
110 | * @param FederatedUserService $federatedUserService |
||
111 | * @param FederatedEventService $federatedEventService |
||
112 | * @param MemberService $memberService |
||
113 | * @param ConfigService $configService |
||
114 | */ |
||
115 | public function __construct( |
||
134 | |||
135 | |||
136 | /** |
||
137 | * @param string $name |
||
138 | * @param FederatedUser|null $owner |
||
139 | * @param bool $personal |
||
140 | * @param bool $local |
||
141 | * |
||
142 | * @return array |
||
143 | * @throws FederatedEventException |
||
144 | * @throws FederatedItemException |
||
145 | * @throws InitiatorNotConfirmedException |
||
146 | * @throws InitiatorNotFoundException |
||
147 | * @throws OwnerNotFoundException |
||
148 | * @throws RemoteInstanceException |
||
149 | * @throws RemoteNotFoundException |
||
150 | * @throws RemoteResourceNotFoundException |
||
151 | * @throws UnknownRemoteException |
||
152 | * @throws RequestBuilderException |
||
153 | */ |
||
154 | public function create( |
||
203 | |||
204 | |||
205 | /** |
||
206 | * @param string $circleId |
||
207 | * |
||
208 | * @return array |
||
209 | * @throws CircleNotFoundException |
||
210 | * @throws FederatedEventException |
||
211 | * @throws FederatedItemException |
||
212 | * @throws InitiatorNotConfirmedException |
||
213 | * @throws InitiatorNotFoundException |
||
214 | * @throws OwnerNotFoundException |
||
215 | * @throws RemoteInstanceException |
||
216 | * @throws RemoteNotFoundException |
||
217 | * @throws RemoteResourceNotFoundException |
||
218 | * @throws RequestBuilderException |
||
219 | * @throws UnknownRemoteException |
||
220 | */ |
||
221 | public function destroy(string $circleId): array { |
||
232 | |||
233 | |||
234 | /** |
||
235 | * @param string $circleId |
||
236 | * @param int $config |
||
237 | * |
||
238 | * @return array |
||
239 | * @throws CircleNotFoundException |
||
240 | * @throws FederatedEventException |
||
241 | * @throws FederatedItemException |
||
242 | * @throws InitiatorNotConfirmedException |
||
243 | * @throws InitiatorNotFoundException |
||
244 | * @throws OwnerNotFoundException |
||
245 | * @throws RemoteInstanceException |
||
246 | * @throws RemoteNotFoundException |
||
247 | * @throws RemoteResourceNotFoundException |
||
248 | * @throws UnknownRemoteException |
||
249 | * @throws RequestBuilderException |
||
250 | */ |
||
251 | public function updateConfig(string $circleId, int $config): array { |
||
262 | |||
263 | |||
264 | /** |
||
265 | * @param string $circleId |
||
266 | * @param string $name |
||
267 | * |
||
268 | * @return array |
||
269 | * @throws CircleNotFoundException |
||
270 | * @throws FederatedEventException |
||
271 | * @throws FederatedItemException |
||
272 | * @throws InitiatorNotConfirmedException |
||
273 | * @throws InitiatorNotFoundException |
||
274 | * @throws OwnerNotFoundException |
||
275 | * @throws RemoteInstanceException |
||
276 | * @throws RemoteNotFoundException |
||
277 | * @throws RemoteResourceNotFoundException |
||
278 | * @throws RequestBuilderException |
||
279 | * @throws UnknownRemoteException |
||
280 | */ |
||
281 | public function updateName(string $circleId, string $name): array { |
||
292 | |||
293 | /** |
||
294 | * @param string $circleId |
||
295 | * @param string $description |
||
296 | * |
||
297 | * @return array |
||
298 | * @throws CircleNotFoundException |
||
299 | * @throws FederatedEventException |
||
300 | * @throws FederatedItemException |
||
301 | * @throws InitiatorNotConfirmedException |
||
302 | * @throws InitiatorNotFoundException |
||
303 | * @throws OwnerNotFoundException |
||
304 | * @throws RemoteInstanceException |
||
305 | * @throws RemoteNotFoundException |
||
306 | * @throws RemoteResourceNotFoundException |
||
307 | * @throws RequestBuilderException |
||
308 | * @throws UnknownRemoteException |
||
309 | */ |
||
310 | public function updateDescription(string $circleId, string $description): array { |
||
321 | |||
322 | /** |
||
323 | * @param string $circleId |
||
324 | * @param array $settings |
||
325 | * |
||
326 | * @return array |
||
327 | * @throws CircleNotFoundException |
||
328 | * @throws FederatedEventException |
||
329 | * @throws FederatedItemException |
||
330 | * @throws InitiatorNotConfirmedException |
||
331 | * @throws InitiatorNotFoundException |
||
332 | * @throws OwnerNotFoundException |
||
333 | * @throws RemoteInstanceException |
||
334 | * @throws RemoteNotFoundException |
||
335 | * @throws RemoteResourceNotFoundException |
||
336 | * @throws RequestBuilderException |
||
337 | * @throws UnknownRemoteException |
||
338 | */ |
||
339 | public function updateSettings(string $circleId, array $settings): array { |
||
350 | |||
351 | |||
352 | /** |
||
353 | * @param string $circleId |
||
354 | * |
||
355 | * @return array |
||
356 | * @throws CircleNotFoundException |
||
357 | * @throws FederatedEventException |
||
358 | * @throws FederatedItemException |
||
359 | * @throws InitiatorNotConfirmedException |
||
360 | * @throws InitiatorNotFoundException |
||
361 | * @throws OwnerNotFoundException |
||
362 | * @throws RemoteInstanceException |
||
363 | * @throws RemoteNotFoundException |
||
364 | * @throws RemoteResourceNotFoundException |
||
365 | * @throws UnknownRemoteException |
||
366 | * @throws RequestBuilderException |
||
367 | */ |
||
368 | public function circleJoin(string $circleId): array { |
||
383 | |||
384 | |||
385 | /** |
||
386 | * @param string $circleId |
||
387 | * @param bool $force |
||
388 | * |
||
389 | * @return array |
||
390 | * @throws CircleNotFoundException |
||
391 | * @throws FederatedEventException |
||
392 | * @throws FederatedItemException |
||
393 | * @throws InitiatorNotConfirmedException |
||
394 | * @throws InitiatorNotFoundException |
||
395 | * @throws OwnerNotFoundException |
||
396 | * @throws RemoteInstanceException |
||
397 | * @throws RemoteNotFoundException |
||
398 | * @throws RemoteResourceNotFoundException |
||
399 | * @throws RequestBuilderException |
||
400 | * @throws UnknownRemoteException |
||
401 | */ |
||
402 | public function circleLeave(string $circleId, bool $force = false): array { |
||
415 | |||
416 | |||
417 | /** |
||
418 | * @param string $circleId |
||
419 | * @param int $filter |
||
420 | * |
||
421 | * @return Circle |
||
422 | * @throws CircleNotFoundException |
||
423 | * @throws InitiatorNotFoundException |
||
424 | * @throws RequestBuilderException |
||
425 | */ |
||
426 | public function getCircle( |
||
439 | |||
440 | |||
441 | /** |
||
442 | * @param Circle|null $circleFilter |
||
443 | * @param Member|null $memberFilter |
||
444 | * @param SimpleDataStore|null $params |
||
445 | * |
||
446 | * @return Circle[] |
||
447 | * @throws InitiatorNotFoundException |
||
448 | * @throws RequestBuilderException |
||
449 | */ |
||
450 | public function getCircles( |
||
480 | |||
481 | |||
482 | /** |
||
483 | * @param Circle $circle |
||
484 | * |
||
485 | * @throws RequestBuilderException |
||
486 | */ |
||
487 | public function confirmName(Circle $circle): void { |
||
496 | |||
497 | /** |
||
498 | * @param Circle $circle |
||
499 | * |
||
500 | * @throws RequestBuilderException |
||
501 | */ |
||
502 | private function confirmDisplayName(Circle $circle) { |
||
525 | |||
526 | |||
527 | /** |
||
528 | * @param Circle $circle |
||
529 | * |
||
530 | * @throws RequestBuilderException |
||
531 | */ |
||
532 | public function generateSanitizedName(Circle $circle) { |
||
533 | $baseSanitizedName = $this->sanitizeName($circle->getName()); |
||
534 | if ($baseSanitizedName === '') { |
||
535 | $baseSanitizedName = substr($circle->getSingleId(), 0, 3); |
||
536 | } |
||
537 | |||
538 | $i = 1; |
||
539 | while (true) { |
||
540 | $testSanitizedName = $baseSanitizedName . (($i > 1) ? ' (' . $i . ')' : ''); |
||
541 | |||
542 | $test = new Circle(); |
||
543 | $test->setSanitizedName($testSanitizedName); |
||
544 | |||
545 | try { |
||
546 | $stored = $this->circleRequest->searchCircle($test); |
||
547 | if ($stored->getSingleId() === $circle->getSingleId()) { |
||
548 | throw new CircleNotFoundException(); |
||
549 | } |
||
550 | } catch (CircleNotFoundException $e) { |
||
551 | $circle->setSanitizedName($testSanitizedName); |
||
552 | |||
553 | return; |
||
554 | } |
||
555 | |||
556 | $i++; |
||
557 | } |
||
558 | } |
||
559 | |||
560 | /** |
||
561 | * @param string $name |
||
562 | * |
||
563 | * @return string |
||
564 | */ |
||
565 | public function sanitizeName(string $name): string { |
||
578 | |||
579 | |||
580 | /** |
||
581 | * @param Circle $circle |
||
582 | * |
||
583 | * @throws MembersLimitException |
||
584 | */ |
||
585 | public function confirmCircleNotFull(Circle $circle): void { |
||
590 | |||
591 | |||
592 | /** |
||
593 | * @param Circle $circle |
||
594 | * |
||
595 | * @return bool |
||
596 | * @throws RequestBuilderException |
||
597 | */ |
||
598 | public function isCircleFull(Circle $circle): bool { |
||
613 | |||
614 | } |
||
615 | |||
616 |
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.