1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
factory.php
См. документацию.
1<?php
2
3namespace Bitrix\Location\Infrastructure\Service\Config;
4
5use Bitrix\Location\Entity\Source;
6use Bitrix\Location\Infrastructure\Service\CustomFieldsService;
7use Bitrix\Location\Infrastructure\Service\LoggerService;
8use Bitrix\Location\Infrastructure\Service\CurrentRegionFinderService;
9use Bitrix\Location\Infrastructure\Service\RecentAddressesService;
10use Bitrix\Location\Infrastructure\SourceCodePicker;
11use Bitrix\Location\Repository\AddressRepository;
12use Bitrix\Location\Exception\ErrorCodes;
13use Bitrix\Location\Repository\Format\DataCollection;
14use Bitrix\Location\Repository\FormatRepository;
15use Bitrix\Location\Repository;
16use Bitrix\Location\Repository\Location\Database;
17use Bitrix\Location\Service\SourceService;
18use Bitrix\Location\Repository\Location\Strategy\Delete;
19use Bitrix\Location\Repository\Location\Strategy\Find;
20use Bitrix\Location\Repository\Location\Strategy\Save;
21use Bitrix\Location\Repository\LocationRepository;
22use Bitrix\Location\Service\AddressService;
23use Bitrix\Location\Infrastructure\Service\ErrorService;
24use Bitrix\Location\Service\FormatService;
25use Bitrix\Location\Service\LocationService;
26use Bitrix\Location\Service\StaticMapService;
27use Bitrix\Main\Config\Option;
28
29class Factory implements IFactory
30{
32 private static $delegate = null;
33
37 public static function createConfig(string $serviceType): Container
38 {
39 $result = null;
40
41 if(self::$delegate !== null && self::$delegate instanceof IFactory)
42 {
43 if($result = self::$delegate::createConfig($serviceType))
44 {
45 return $result;
46 }
47 }
48
49 return new Container(
50 static::getServiceConfig($serviceType)
51 );
52 }
53
57 public static function setDelegate(IFactory $factory): void
58 {
59 self::$delegate = $factory;
60 }
61
62 protected static function getLogLevel(): int
63 {
64 return (int)Option::get('location', 'log_level', LoggerService\LogLevel::ERROR);
65 }
66
67 protected static function getServiceConfig(string $serviceType)
68 {
69 $result = [];
70
71 switch ($serviceType)
72 {
73 case LoggerService::class:
74 $result = [
75 'logger' => new LoggerService\CEventLogger(),
76 'logLevel'=> static::getLogLevel(),
77 'eventsToLog' => []
78 ];
79 break;
80
81 case ErrorService::class:
82 $result = [
83 'logErrors' => true,
84 'throwExceptionOnError' => false
85 ];
86 break;
87
88 case FormatService::class:
89 $result = [
90 'repository' => new FormatRepository([
91 'dataCollection' => DataCollection::class //Format data collection
92 ]),
94 ];
95 break;
96
97 case AddressService::class:
98 $result = [
99 'repository' => new AddressRepository()
100 ];
101 break;
102
103 case StaticMapService::class:
104 case SourceService::class:
105 $result = [
106 'source' => self::obtainSource()
107 ];
108 break;
109
110 case LocationService::class:
111 $result = [
112 'repository' => static::createLocationRepository(
113 self::obtainSource()
114 )
115 ];
116 break;
117
118 case CurrentRegionFinderService::class:
119 case CustomFieldsService::class:
120 case RecentAddressesService::class:
121 break;
122
123 default:
124 throw new \LogicException("Unknown service type \"${serviceType}\"", ErrorCodes::SERVICE_CONFIG_FABRIC_WRONG_SERVICE);
125 }
126
127 return $result;
128 }
129
134 private static function createLocationRepository(Source $source = null): LocationRepository
135 {
136 $cacheTTL = 2592000; //month
137 $poolSize = 30;
138 $pool = new Repository\Location\Cache\Pool($poolSize);
139
140 $cache = new Repository\Location\Cache(
141 $pool,
142 $cacheTTL,
143 'locationRepositoryCache',
144 \Bitrix\Main\Data\Cache::createInstance(),
146 );
147
148 $repositories = [
149 $cache,
150 new Database()
151 ];
152
153 if($source)
154 {
155 $repositories[] = $source->makeRepository();
156 }
157
158 return new LocationRepository(
159 new Find($repositories),
160 new Save($repositories),
161 new Delete($repositories)
162 );
163 }
164
168 private static function obtainSource(): ?Source
169 {
170 static $result;
171 if (!is_null($result))
172 {
173 return $result;
174 }
175
176 $result = (new Repository\SourceRepository(new Source\OrmConverter()))
177 ->findByCode(SourceCodePicker::getSourceCode())
178 ;
179
180 return $result && $result->isAvailable() ? $result : null;
181 }
182}
static getCurrent(string $regionId=null, string $siteId='')
Определения formatcode.php:19
static setDelegate(IFactory $factory)
Определения factory.php:57
static createConfig(string $serviceType)
Определения factory.php:37
static getServiceConfig(string $serviceType)
Определения factory.php:67
static getInstance()
Определения eventmanager.php:31
$result
Определения get_property_values.php:14
Определения aliases.php:105
return false
Определения prolog_main_admin.php:185