1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ServiceFactory.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Socialnetwork\Control;
6
7use Bitrix\Main\DI\ServiceLocator;
8use Bitrix\Main\ObjectNotFoundException;
9use Bitrix\Socialnetwork\Control\Member\AbstractMemberService;
10use Bitrix\Socialnetwork\Internals\Registry\GroupRegistry;
11use Bitrix\Socialnetwork\Item\Workgroup\Type;
12
13final class ServiceFactory
14{
15 protected static ?self $instance = null;
16
17 public static function getInstance(): self
18 {
19 if (self::$instance === null)
20 {
21 self::$instance = new self();
22 }
23
24 return self::$instance;
25 }
26
28 {
29 $entity = GroupRegistry::getInstance()->get($entityId);
30 if ($entity === null)
31 {
32 throw new ObjectNotFoundException("Entity {$entityId} not found");
33 }
34
35 $type = $entity->getType();
36 if ($type === null)
37 {
38 throw new ObjectNotFoundException("Entity {$entityId} has wrong type");
39 }
40
42 }
43
45 {
46 $locator = ServiceLocator::getInstance();
47
48 return match ($type)
49 {
50 Type::Collab => $locator->get('socialnetwork.collab.member.facade'),
51 default => $locator->get('socialnetwork.group.member.service'),
52 };
53 }
54
59 {
60 $entity = GroupRegistry::getInstance()->get($entityId);
61 if ($entity === null)
62 {
63 throw new ObjectNotFoundException("Entity {$entityId} not found");
64 }
65
66 $type = $entity->getType();
67 if ($type === null)
68 {
69 throw new ObjectNotFoundException("Entity {$entityId} has wrong type");
70 }
71
72 return $this->getServiceByEntityType($type);
73 }
74
76 {
77 $locator = ServiceLocator::getInstance();
78
79 return match ($type)
80 {
81 Type::Collab => $locator->get('socialnetwork.collab.service'),
82 default => $locator->get('socialnetwork.group.service'),
83 };
84 }
85}
$type
Определения options.php:106
getMemberServiceByEntityType(Type $type)
Определения ServiceFactory.php:44
getMemberService(int $entityId)
Определения ServiceFactory.php:27
getServiceByEntityId(int $entityId)
Определения ServiceFactory.php:58
$entity
Определения collection.php:2
$entityId
Определения payment.php:4