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/ilovecveti.ru/bitrix/modules/calendar/lib/sync/factories/ |
Upload File : |
<?php namespace Bitrix\Calendar\Sync\Factories; use Bitrix\Calendar\Core\Base\BaseException; use Bitrix\Calendar\Core\Builders\Builder; use Bitrix\Calendar\Sync; class FactoryBuilder implements Builder { /** * @var FactoryBase */ private FactoryBase $factory; /** * @param string $accountType * @param Sync\Connection\Connection $connection * @param Sync\Util\Context $context * * @return FactoryBase * @todo an unsupported type may arrive. In this case return null */ public static function create( string $accountType, Sync\Connection\Connection $connection, Sync\Util\Context $context ): ?FactoryBase { return self::getClassName($accountType) ? (new self($accountType, $connection, $context))->build() : null; } /** * @param string $accountType * @param Sync\Connection\Connection $connection * @param Sync\Util\Context $context * * @throws BaseException */ public function __construct( string $accountType, Sync\Connection\Connection $connection, Sync\Util\Context $context ) { $className = self::getClassName($accountType); if (!$className) { throw new BaseException('Factory for accout type is not found'); } $this->factory = new $className($connection, $context); } /** * @param string $parentService * @return array */ public static function getAvailableServices(string $parentService): array { return array_diff(array_keys(self::getServiceMap()), [$parentService]); } /** * @return string[] */ private static function getServiceMap(): array { return [ Sync\Google\Factory::SERVICE_NAME => Sync\Google\Factory::class, Sync\Office365\Factory::SERVICE_NAME => Sync\Office365\Factory::class, Sync\Icloud\Factory::SERVICE_NAME => Sync\Icloud\Factory::class, ]; } /** * @param string $accountType * @return string|null */ public static function getClassName(string $accountType): ?string { return self::getServiceMap()[$accountType] ?? null; } /** * @return FactoryBase */ public function build(): FactoryBase { return $this->factory; } /** * @param $serviceName * @return bool */ public static function checkService($serviceName): bool { return array_key_exists($serviceName, self::getServiceMap()); } }