Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/socialnetwork/lib/Control/ |
Upload File : |
<?php declare(strict_types=1); namespace Bitrix\Socialnetwork\Control; use Bitrix\Main\DI\ServiceLocator; use Bitrix\Main\ObjectNotFoundException; use Bitrix\Socialnetwork\Control\Member\AbstractMemberService; use Bitrix\Socialnetwork\Internals\Registry\GroupRegistry; use Bitrix\Socialnetwork\Item\Workgroup\Type; final class ServiceFactory { protected static ?self $instance = null; public static function getInstance(): self { if (self::$instance === null) { self::$instance = new self(); } return self::$instance; } public function getMemberService(int $entityId): AbstractMemberService { $entity = GroupRegistry::getInstance()->get($entityId); if ($entity === null) { throw new ObjectNotFoundException("Entity {$entityId} not found"); } $type = $entity->getType(); if ($type === null) { throw new ObjectNotFoundException("Entity {$entityId} has wrong type"); } return $this->getMemberServiceByEntityType($type); } public function getMemberServiceByEntityType(Type $type): AbstractMemberService { $locator = ServiceLocator::getInstance(); return match ($type) { Type::Collab => $locator->get('socialnetwork.collab.member.facade'), default => $locator->get('socialnetwork.group.member.service'), }; } /** * @throws ObjectNotFoundException */ public function getServiceByEntityId(int $entityId): AbstractGroupService { $entity = GroupRegistry::getInstance()->get($entityId); if ($entity === null) { throw new ObjectNotFoundException("Entity {$entityId} not found"); } $type = $entity->getType(); if ($type === null) { throw new ObjectNotFoundException("Entity {$entityId} has wrong type"); } return $this->getServiceByEntityType($type); } public function getServiceByEntityType(Type $type): AbstractGroupService { $locator = ServiceLocator::getInstance(); return match ($type) { Type::Collab => $locator->get('socialnetwork.collab.service'), default => $locator->get('socialnetwork.group.service'), }; } }