Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
factorybuilder.php
1<?php
2
4
8
9class FactoryBuilder implements Builder
10{
14 private FactoryBase $factory;
15
24 public static function create(
25 string $accountType,
26 Sync\Connection\Connection $connection,
27 Sync\Util\Context $context
28 ): ?FactoryBase
29 {
30 return self::getClassName($accountType)
31 ? (new self($accountType, $connection, $context))->build()
32 : null;
33 }
34
42 public function __construct(
43 string $accountType,
44 Sync\Connection\Connection $connection,
45 Sync\Util\Context $context
46 )
47 {
48 $className = self::getClassName($accountType);
49 if (!$className)
50 {
51 throw new BaseException('Factory for accout type is not found');
52 }
53 $this->factory = new $className($connection, $context);
54 }
55
60 public static function getAvailableServices(string $parentService): array
61 {
62 return array_diff(array_keys(self::getServiceMap()), [$parentService]);
63 }
64
68 private static function getServiceMap(): array
69 {
70 return [
71 Sync\Google\Factory::SERVICE_NAME => Sync\Google\Factory::class,
72 Sync\Office365\Factory::SERVICE_NAME => Sync\Office365\Factory::class,
73 Sync\Icloud\Factory::SERVICE_NAME => Sync\Icloud\Factory::class,
74 ];
75 }
76
81 public static function getClassName(string $accountType): ?string
82 {
83 return self::getServiceMap()[$accountType] ?? null;
84 }
85
89 public function build(): FactoryBase
90 {
91 return $this->factory;
92 }
93
98 public static function checkService($serviceName): bool
99 {
100 return array_key_exists($serviceName, self::getServiceMap());
101 }
102}
__construct(string $accountType, Sync\Connection\Connection $connection, Sync\Util\Context $context)
static create(string $accountType, Sync\Connection\Connection $connection, Sync\Util\Context $context)
static getAvailableServices(string $parentService)