Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
manager.php
1<?php
2
4
12use Exception;
13
15{
16 private static $workspaces = null;
17 private static $availableComponents = null;
18
19 private static function getWorkspaces(): array
20 {
21 if (self::$workspaces == null)
22 {
23 self::$workspaces = [];
24 $events = EventManager::getInstance()->findEventHandlers('mobileapp', 'onJNComponentWorkspaceGet');
25 foreach ($events as $event)
26 {
27 $path = ExecuteModuleEventEx($event);
28 if (!in_array($path, self::$workspaces))
29 {
30 self::$workspaces[] = $path;
31 }
32 }
33 }
34
35 return self::$workspaces;
36 }
37
42 private static function fetchComponents(): ?array
43 {
44 if (self::$availableComponents == null)
45 {
46 self::$availableComponents = [];
47 $rawComponentList = [];
48 $workspaces = self::getWorkspaces();
49 foreach ($workspaces as $path)
50 {
51 $componentDir = new Directory(Application::getDocumentRoot() . $path . '/components/');
52 if (!$componentDir->isExists())
53 {
54 continue;
55 }
56
57 $namespaces = $componentDir->getChildren();
58 foreach ($namespaces as $NSDir)
59 {
60 if (!$NSDir->isDirectory())
61 {
62 continue;
63 }
64
65 $namespaceItems = $NSDir->getChildren();
66 $namespace = $NSDir->getName();
67 foreach ($namespaceItems as $item)
68 {
69 try
70 {
71 $component = new Component($item->getPath(), $namespace);
72 $name = $item->getName();
73 $name = ($namespace == 'bitrix' ? $name : $namespace . ':' . $name);
74 $rawComponentList[$name] = $component;
75 } catch (Exception $e)
76 {
77
78 }
79 }
80 }
81 }
82
83 self::$availableComponents = $rawComponentList;
84
85 }
86
87 return self::$availableComponents;
88 }
89
94 public static function getExtensionPath($ext)
95 {
97 $extensionPath = null;
98 $workspaces = self::getWorkspaces();
99 foreach ($workspaces as $path)
100 {
101 $extensionDir = new Directory(Application::getDocumentRoot() . $path . '/extensions/' . $desc['relativePath']);
102 if ($extensionDir->isExists())
103 {
104 $extensionPath = $extensionDir->getPath();
105 }
106 }
107
108 return $extensionPath;
109 }
110
111 public static function getExtensionResourceList($ext): array
112 {
113 $extList = is_array($ext) ? $ext : [$ext];
114
115 $extensions = [];
116 $alreadyResolved = [];
117
118 foreach ($extList as $ext)
119 {
120 if (!Manager::getExtensionPath($ext))
121 {
122 continue;
123 }
124
125 Extension::getResolvedDependencyList($ext, $extensions, $alreadyResolved);
126 }
127
128 $result = [
129 'js' => [],
130 'messages' => [],
131 ];
132
133 foreach ($extensions as $extName)
134 {
135 $extension = new Extension($extName);
136 $result['messages'] = array_merge($result['messages'], $extension->getLangMessages());
137 $result['js'][] = $extension->getRelativePathToFile();
138 }
139
140 return $result;
141 }
142
148 public static function getComponentVersion($componentName): string
149 {
150 $component = Component::createInstanceByName($componentName);
151 if ($component)
152 {
153 return $component->getVersion();
154 }
155
156 return '1.0';
157 }
158
164 public static function getComponentPath($componentName): string
165 {
166 $component = Component::createInstanceByName($componentName);
167 if ($component)
168 {
169 return $component->getPublicPath();
170 }
171
172 return '';
173 }
174
179 public static function getAvailableComponents(): ?array
180 {
181 return self::fetchComponents();
182 }
183
189 public static function getComponentByName($name): ?Component {
190 $name = str_replace("bitrix:", "", $name);
191 $components = self::fetchComponents();
192 if (array_key_exists($name, $components)) {
193 return $components[$name];
194 }
195
196 return null;
197 }
198
199
200}
static createInstanceByName($name, string $namespace='bitrix')
Definition component.php:80
static getResolvedDependencyList($name, &$list=[], &$alreadyResolved=[], $margin=0)
static getComponentVersion($componentName)
Definition manager.php:148
static getComponentPath($componentName)
Definition manager.php:164
static extractEntityDescription($entityIdentifier, $defaultNamespace="bitrix")
Definition utils.php:15