1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
base.php
См. документацию.
1<?php
2
4
14
15abstract class Base
16{
17 protected static array $modificationDates = [];
18 protected static array $dependencies = [];
19 protected static array $expandedDependencies = [];
20 protected static array $configs = [];
21 protected $path;
22 protected $namespace;
23 protected $baseFileName;
24 public $name;
25 private $config;
26
27 protected function getConfig(): ?array
28 {
29 if ($this->config == null)
30 {
31 if (!isset(self::$configs[$this->path]))
32 {
33 $this->config = [];
34 $file = new File("$this->path/deps.php");
35 $result = [];
36 if ($file->isExists())
37 {
38 $this->config = include($file->getPath());
39 if (!is_array($this->config))
40 {
41 $this->config = [];
42 }
43 }
44
45 self::$configs[$this->path] = $this->config;
46 }
47 else
48 {
49 $this->config = self::$configs[$this->path];
50 }
51 }
52
53 return $this->config;
54 }
55
56 public function getModificationMarker()
57 {
58 if (defined("JN_DEV_RELOAD"))
59 {
60 return "1.0";
61 }
62
63 $fullyQualifiedName = $this->getFullyQualifiedName();
64
65 if (!empty(static::$modificationDates[$fullyQualifiedName]))
66 {
67 return static::$modificationDates[$fullyQualifiedName];
68 }
69
70 $marks = [];
71
72 $file = new File("{$this->path}/{$this->baseFileName}.js");
73 if ($file->isExists())
74 {
75 $marks[] = Utils::getFileHash($file);
76 }
77
78 $langDirectory = new Directory("{$this->path}/lang/");
79 if ($langDirectory->isExists())
80 {
81 $langs = $langDirectory->getChildren();
82 foreach ($langs as $lang)
83 {
84 if ($lang->isDirectory())
85 {
86 $langFile = new File($lang->getPath() . "/{$this->baseFileName}.php");
87 if ($langFile->isExists())
88 {
89 $marks[] = Utils::getFileHash($langFile);
90 }
91 }
92 }
93 }
94
95 $this->onBeforeModificationMarkerSave($marks);
96 $value = count($marks) === 1 ? $marks[0] : md5(implode("/", $marks));
97
98 static::$modificationDates[$fullyQualifiedName] = $value;
99
100 return $value;
101 }
102
103 public function getFullyQualifiedName(): string
104 {
105 return "$this->namespace:$this->name";
106 }
107
108 public function getDependencies()
109 {
110 $fullyQualifiedName = $this->getFullyQualifiedName();
111 static::$dependencies[$fullyQualifiedName] ??= array_values($this->resolveDependencies());
112
113 return static::$dependencies[$fullyQualifiedName];
114 }
115
116 public function getPath()
117 {
118 $relativePath = str_replace(Application::getDocumentRoot(), "", "{$this->path}/");
119
120 return Path::normalize($relativePath);
121 }
122
123 public function getRelativePathToFile()
124 {
125 $relativePath = $this->getPath() . "/{$this->baseFileName}.js";
126
127 return Path::normalize($relativePath);
128 }
129
130 public function getLangMessages()
131 {
132 $langPhrases = Localization\Loc::loadLanguageFile("{$this->path}/{$this->baseFileName}.php");
133
134 return $langPhrases ?: [];
135 }
136
137 public function getDependencyList()
138 {
139 $config = $this->getConfig();
140 $list = [];
141 $result = [];
142 if (is_array($config))
143 {
144 if (array_keys($config) !== range(0, count($config) - 1))
145 {
146 if (array_key_exists('extensions', $config))
147 {
148 $list = $config['extensions'];
149 }
150 }
151 else
152 {
153 $list = $config;
154 }
155 }
156 if (!empty($list))
157 {
158 foreach ($list as $ext)
159 {
160 $result[] = Base::expandDependency($ext);
161 }
162
163 if (!empty($result))
164 {
165 $result = array_merge(...$result);
166 }
167 }
168
169 return $result;
170 }
171
172 public function getBundleFiles(): array
173 {
174 $config = $this->getConfig();
175 $list = [];
176 if (isset($config["bundle"]))
177 {
178 $list = array_map(function ($file) {
179 $path = Path::normalize($this->path . "/$file");
180 if (Path::getExtension($path) !== "js")
181 {
182 $path .= ".js";
183 }
184
185 return $path;
186 }, $config["bundle"]);
187 }
188
189 return $list;
190 }
191
192 public function getComponentDependencies(): ?array
193 {
194 $config = $this->getConfig();
195 $result = [];
196 if (is_array($config))
197 {
198 if (array_keys($config) !== range(0, count($config) - 1))
199 {
200 if (isset($config['components']))
201 {
202 if (is_array($config['components']))
203 {
204 return $config['components'];
205 }
206 }
207 }
208 else
209 {
210 $result = null;
211 }
212
213 }
214
215 return $result;
216 }
217
223 private static function expandDependency($ext): array
224 {
225
226 $result = [];
227
228 if (!is_string($ext))
229 {
230 return [];
231 }
232
233 if (isset(self::$expandedDependencies[$ext]))
234 {
235 return self::$expandedDependencies[$ext];
236 }
237
238 $findChildren = false;
239 $relativeExtDir = $ext;
240
241 if (mb_strpos($ext, "*") === (mb_strlen($ext) - 1))
242 {
243 $relativeExtDir = str_replace(["/*", "*"], "", $ext);
244 $findChildren = true;
245 }
246
247 $absolutePath = Manager::getExtensionPath($relativeExtDir);
248 if ($findChildren && $absolutePath != null)
249 {
250 $dir = new Directory($absolutePath);
251 $items = $dir->getChildren();
252 for ($i = 0, $l = count($items); $i < $l; $i++)
253 {
255 $entry = $items[$i];
256 if ($entry->isDirectory())
257 {
258 $toAdd = $entry->getChildren();
259 $extensionFile = new File($entry->getPath() . '/extension.js');
260 if ($extensionFile->isExists())
261 {
262 $result[] = $extensionFile->getPath();
263 }
264
265 $l += count($toAdd);
266 $items = array_merge($items, $toAdd);
267 }
268 }
269
270 $result = array_map(function ($path) use ($absolutePath, $relativeExtDir) {
271 return str_replace([$absolutePath, "/extension.js"], [$relativeExtDir, ""], $path);
272 }, $result);
273 }
274
275 $rootExtension = new File($absolutePath . '/extension.js');
276 if ($rootExtension->isExists())
277 {
278 $result[] = $relativeExtDir;
279 }
280
281 self::$expandedDependencies[$ext] = $result;
282
283 return $result;
284 }
285
287 {
288 $langPhrases = $this->getLangMessages();
289 if (!empty($langPhrases))
290 {
291 $jsonLangMessages = Utils::jsonEncode($langPhrases, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE);
292
293 return <<<JS
294BX.message($jsonLangMessages);
295JS;
296 }
297
298 return "";
299 }
300
301 abstract protected function onBeforeModificationMarkerSave(array &$value);
302
303 abstract protected function resolveDependencies();
304
305}
Определения fileentry.php:6
Определения path.php:12
static loadLanguageFile($file, $language=null, $normalize=true)
Определения loc.php:225
static array $expandedDependencies
Определения base.php:19
static array $dependencies
Определения base.php:18
getLangDefinitionExpression()
Определения base.php:286
static array $modificationDates
Определения base.php:17
static array $configs
Определения base.php:20
static getExtensionPath($ext)
Определения manager.php:97
static getFileHash(File $file)
Определения utils.php:52
static jsonEncode($string, $options=JSON_HEX_TAG|JSON_HEX_AMP|JSON_PRETTY_PRINT|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_UNESCAPED_UNICODE)
Определения utils.php:47
$langFile
Определения .description.php:2
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$absolutePath
Определения folder_edit.php:53
$result
Определения get_property_values.php:14
if(!defined('SITE_ID')) $lang
Определения include.php:91
$l
Определения options.php:783
Определения Image.php:9
$dir
Определения quickway.php:303
$config
Определения quickway.php:69
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$items
Определения template.php:224
$langs
Определения options.php:141
path
Определения template_copy.php:201