Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
configuration.php
1<?
2
4
7
8final class Configuration
9{
10 static private $loaded = false;
11 static private $entities = [];
12 static private $providers = [];
13 static private $filters = [];
14 static private $extensions = [];
15
16 public static function getExtensions(): array
17 {
18 self::load();
19
20 return self::$extensions;
21 }
22
30 public static function getProvider(Entity $entity)
31 {
32 $entityId = $entity->getId();
33 $options = $entity->getOptions();
34
35 self::load();
36
37 if (!is_string($entityId) || !isset(self::$entities[$entityId]))
38 {
39 return null;
40 }
41
42 if (array_key_exists($entityId, self::$providers))
43 {
44 return self::$providers[$entityId];
45 }
46
47 $substituteEntityId = $entity->getSubstituteEntityId();
48 if (
49 is_string($substituteEntityId)
50 && isset(self::$entities[$substituteEntityId]['substitutes'])
51 && self::$entities[$substituteEntityId]['substitutes'] === $entityId
52 )
53 {
54 $moduleId = self::$entities[$substituteEntityId]['provider']['moduleId'] ?? null;;
55 $className = self::$entities[$substituteEntityId]['provider']['className'] ?? null;
56 }
57 else
58 {
59 $moduleId = self::$entities[$entityId]['provider']['moduleId'] ?? null;;
60 $className = self::$entities[$entityId]['provider']['className'] ?? null;
61 }
62
63 self::$providers[$entityId] = self::createProvider($moduleId, $className, $options);
64
65 return self::$providers[$entityId];
66 }
67
73 public static function getFilters(string $entityId, array $filterOptions = []): ?array
74 {
75 self::load();
76
77 if (!is_string($entityId) || !isset(self::$entities[$entityId]))
78 {
79 return null;
80 }
81
82 $filterConfigs = self::$filters[$entityId] ?? null;
83 if (!is_array($filterConfigs) || count($filterConfigs) === 0)
84 {
85 return null;
86 }
87
88 $filters = [];
89 foreach ($filterOptions as $filterOption)
90 {
91 if (!array_key_exists($filterOption['id'], $filterConfigs))
92 {
93 continue;
94 }
95
96 $moduleId = FilterControllerResolver::getModuleId($filterOption['id']);
97 $className = $filterConfigs[$filterOption['id']]['className'] ?? null;
98 $options = isset($filterOption['options']) && is_array($filterOption['options']) ? $filterOption['options'] : [];
99
100 $filters[] = self::createFilter($moduleId, $className, $options);
101 }
102
103 return $filters;
104 }
105
106 public static function getEntities()
107 {
108 self::load();
109
110 return self::$entities;
111 }
112
113 private static function load()
114 {
115 if (self::$loaded)
116 {
117 return;
118 }
119
120 foreach (ModuleManager::getInstalledModules() as $moduleId => $moduleDesc)
121 {
122 $settings = \Bitrix\Main\Config\Configuration::getInstance($moduleId)->get('ui.entity-selector');
123 if (empty($settings) || !is_array($settings))
124 {
125 continue;
126 }
127
128 if (!empty($settings['extensions']) && is_array($settings['extensions']))
129 {
130 self::$extensions = array_merge(self::$extensions, $settings['extensions']);
131 }
132
133 if (!empty($settings['entities']) && is_array($settings['entities']))
134 {
135 foreach ($settings['entities'] as $entity)
136 {
137 if (is_array($entity) && !empty($entity["entityId"]) && is_string($entity["entityId"]))
138 {
139 self::$entities[$entity["entityId"]] = $entity;
140 }
141 }
142 }
143
144 if (!empty($settings['filters']) && is_array($settings['filters']))
145 {
146 foreach ($settings['filters'] as $filter)
147 {
148 if (
149 is_array($filter)
150 && !empty($filter['id'])
151 && is_string($filter['id'])
152 && !empty($filter['entityId'])
153 && is_string($filter['entityId'])
154 && !empty($filter['className'])
155 && is_string($filter['className'])
156 )
157 {
158 self::$filters[$filter['entityId']][$filter['id']] = $filter;
159 }
160 }
161 }
162 }
163
164 self::$loaded = true;
165 }
166
167 private static function createProvider($moduleId, $className, $options = []): ?BaseProvider
168 {
169 if (!is_string($className))
170 {
171 return null;
172 }
173
174 if (is_string($moduleId))
175 {
176 Loader::includeModule($moduleId);
177 }
178
179 try
180 {
181 $reflectionClass = new \ReflectionClass($className);
182 if ($reflectionClass->isAbstract())
183 {
184 return null;
185 }
186
187 if (!$reflectionClass->isSubclassOf(BaseProvider::class))
188 {
189 return null;
190 }
191
193 $provider = $reflectionClass->newInstance($options);
194
195 return $provider;
196
197 }
198 catch (\ReflectionException $exception)
199 {
200
201 }
202
203 return null;
204 }
205
206 private static function createFilter($moduleId, $className, $options = []): ?BaseFilter
207 {
208 if (!is_string($className))
209 {
210 return null;
211 }
212
213 if (is_string($moduleId))
214 {
215 Loader::includeModule($moduleId);
216 }
217
218 try
219 {
220 $reflectionClass = new \ReflectionClass($className);
221 if ($reflectionClass->isAbstract())
222 {
223 return null;
224 }
225
226 if (!$reflectionClass->isSubclassOf(BaseFilter::class))
227 {
228 return null;
229 }
230
232 $filter = $reflectionClass->newInstance($options);
233
234 return $filter;
235 }
236 catch (\ReflectionException $exception)
237 {
238
239 }
240
241 return null;
242 }
243}
static getFilters(string $entityId, array $filterOptions=[])