1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
manager.php
См. документацию.
1<?php
2
3namespace Bitrix\MobileApp\Janative;
4
5use Bitrix\Main\Application;
6use Bitrix\Main\Config\Option;
7use Bitrix\Main\EventManager;
8use Bitrix\Main\IO\Directory;
9use Bitrix\Main\IO\FileNotFoundException;
10use Bitrix\MobileApp\Janative\Entity\Component;
11use Bitrix\MobileApp\Janative\Entity\Extension;
12use Exception;
13
15{
16 private static ?array $workspaces = null;
17 private static ?array $availableComponents = null;
18 private static array $extensionPaths = [];
19 private static ?bool $isBundleEnabled = null;
20
21 private static function getWorkspaces(): array
22 {
23 if (self::$workspaces == null)
24 {
25 self::$workspaces = [];
26 $events = EventManager::getInstance()->findEventHandlers('mobileapp', 'onJNComponentWorkspaceGet');
27 foreach ($events as $event)
28 {
30 if (!in_array($path, self::$workspaces))
31 {
32 self::$workspaces[] = $path;
33 }
34 }
35 }
36
37 return self::$workspaces;
38 }
39
44 private static function fetchComponents(): ?array
45 {
46 if (self::$availableComponents == null)
47 {
48 self::$availableComponents = [];
49 $rawComponentList = [];
50 $workspaces = self::getWorkspaces();
51 foreach ($workspaces as $path)
52 {
53 $componentDir = new Directory(Application::getDocumentRoot() . $path . '/components/');
54 if (!$componentDir->isExists())
55 {
56 continue;
57 }
58
59 $namespaces = $componentDir->getChildren();
60 foreach ($namespaces as $NSDir)
61 {
62 if (!$NSDir->isDirectory())
63 {
64 continue;
65 }
66
67 $namespaceItems = $NSDir->getChildren();
68 $namespace = $NSDir->getName();
69 foreach ($namespaceItems as $item)
70 {
71 try
72 {
73 $component = new Component($item->getPath(), $namespace);
74 $name = $item->getName();
75 $name = ($namespace == 'bitrix' ? $name : $namespace . ':' . $name);
76 $rawComponentList[$name] = $component;
77 }
78 catch (Exception $e)
79 {
80
81 }
82 }
83 }
84 }
85
86 self::$availableComponents = $rawComponentList;
87
88 }
89
90 return self::$availableComponents;
91 }
92
97 public static function getExtensionPath($ext): array|string|null
98 {
99 if (!isset(self::$extensionPaths[$ext]))
100 {
102 $workspaces = self::getWorkspaces();
103 foreach ($workspaces as $path)
104 {
105 $extensionDir = new Directory(Application::getDocumentRoot() . $path . '/extensions/' . $desc['relativePath']);
106 if ($extensionDir->isExists())
107 {
108 self::$extensionPaths[$ext] = $extensionDir->getPath();
109 break;
110 }
111 }
112 }
113
114 return self::$extensionPaths[$ext] ?? null;
115 }
116
117 public static function getExtensionResourceList($ext): array
118 {
119 $extList = is_array($ext) ? $ext : [$ext];
120
121 $extensions = [];
122 $alreadyResolved = [];
123
124 foreach ($extList as $extension)
125 {
126 if (!Manager::getExtensionPath($extension))
127 {
128 continue;
129 }
130
131 Extension::getResolvedDependencyList($extension, $extensions, $alreadyResolved);
132 }
133
134 $result = [
135 'js' => [],
136 'messages' => [],
137 ];
138
139 foreach ($extensions as $extName)
140 {
141 $extension = Extension::getInstance($extName);
142 $result['messages'] = array_merge($result['messages'], $extension->getLangMessages());
143 $result['js'][] = $extension->getRelativePathToFile();
144 }
145
146 return $result;
147 }
148
154 public static function getComponentVersion($componentName): string
155 {
156 $component = Component::createInstanceByName($componentName);
157 if ($component)
158 {
159 return $component->getVersion();
160 }
161
162 return '1.0';
163 }
164
170 public static function getComponentPath($componentName): string
171 {
172 $component = Component::createInstanceByName($componentName);
173 if ($component)
174 {
175 return $component->getPublicPath();
176 }
177
178 return '';
179 }
180
185 public static function getAvailableComponents(): ?array
186 {
187 return self::fetchComponents();
188 }
189
195 public static function getComponentByName($name): ?Component
196 {
197 $name = str_replace("bitrix:", "", $name);
198 $components = self::fetchComponents();
199
200 return $components[$name] ?? null;
201 }
202
203 public static function isBundleEnabled(): bool
204 {
205 if (self::$isBundleEnabled === null)
206 {
207 self::$isBundleEnabled = Option::get('mobileapp', 'jn_bundle_enabled', 'N') === 'Y';
208 }
209
210 return self::$isBundleEnabled;
211 }
212}
$path
Определения access_edit.php:21
static getInstance()
Определения eventmanager.php:31
static getResolvedDependencyList($name, &$list=[], &$alreadyResolved=[], $margin=0)
Определения extension.php:155
static getInstance($identifier)
Определения extension.php:27
static getExtensionResourceList($ext)
Определения manager.php:117
static getExtensionPath($ext)
Определения manager.php:97
static getAvailableComponents()
Определения manager.php:185
static getComponentVersion($componentName)
Определения manager.php:154
static getComponentPath($componentName)
Определения manager.php:170
static isBundleEnabled()
Определения manager.php:203
static getComponentByName($name)
Определения manager.php:195
static extractEntityDescription($entityIdentifier, string $defaultNamespace="bitrix")
Определения utils.php:16
$componentName
Определения component_props2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
$name
Определения menu_edit.php:35
if(mb_strlen($order)< 6) $desc
Определения payment.php:44
$event
Определения prolog_after.php:141