1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
converter.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Web\WebPacker;
4
5use Bitrix\Main\InvalidOperationException;
6use Bitrix\Main\Localization\Loc;
7
14{
15 const CORE_EXTENSION = 'ui.webpacker';
16
17 protected static $hasCoreExtension = false;
18
25 public static function stringify(Builder $builder)
26 {
27 self::$hasCoreExtension = $builder->hasCoreExtension();
28 if (self::$hasCoreExtension)
29 {
31 'address' => Builder::getDefaultSiteUri()
32 ]);
33 $content = "var webPacker = $content;" . self::getEol();
34 }
35 else
36 {
37 $content = '';
38 }
39
40 foreach ($builder->getModules() as $module)
41 {
42 $moduleContent = self::encodeModule($module);
43 $content .= self::wrap($moduleContent) . self::getEol();
44 }
45
46 return self::wrap($content);
47 }
48
55 protected static function wrap($content)
56 {
57 return <<<EOD
58;(function () {
60})();
61EOD;
62
63 }
64
71 protected static function encodeModule(Module $module)
72 {
73 $name = $module->getName();
74 $content = '';
75 if (!self::isCoreExtension($name) && self::$hasCoreExtension)
76 {
77 $name = \CUtil::jsEscape($name);
78 $content = "var module = new webPacker.module('$name');" . self::getEol(1);
79
80 if ($module->getProfile())
81 {
82 $properties = $module->getProfile()->getProperties();
83 if (!empty($properties))
84 {
85 $properties = JsonEncoder::encode($properties);
86 $content .= "module.setProperties($properties);" . self::getEol(1);
87 }
88 }
89 }
90
91 if ($module->getPackage())
92 {
93 $content .= self::encodePackage($module->getPackage(), $module->getProfile());
94 }
95 if ($module->getProfile())
96 {
97 $method = $module->getProfile()->getCallMethod();
98 if ($method)
99 {
100 $parameter = $module->getProfile()->getCallParameter();
101 $parameter = $parameter ? JsonEncoder::encode($parameter) : '{}';
102 $content .= "$method($parameter);";
103 }
104 }
105
106 return $content;
107 }
108
116 protected static function encodePackage(Resource\Package $package, Resource\Profile $profile = null)
117 {
118 $content = '';
119 foreach ($package::getOrderedTypeList() as $type)
120 {
121 $assets = $package->getAssets($type);
122 if (empty($assets))
123 {
124 continue;
125 }
126
127 switch ($type)
128 {
129 case Resource\Asset::CSS:
130 case Resource\Asset::LAYOUT:
131 if (!self::$hasCoreExtension)
132 {
133 throw new InvalidOperationException("Resource of type `$type` not allowed without core extension.");
134 }
135
136 $resources = $list = JsonEncoder::encode($package->toArray($type));
137 $content .= "module.loadResources($resources);" . self::getEol();
138 break;
139
140 case Resource\Asset::JS:
141 foreach ($assets as $asset)
142 {
143 $content .= $asset->getContent() . self::getEol();
144 }
145 break;
146
147 case Resource\Asset::LANG:
148 if (!self::$hasCoreExtension)
149 {
150 throw new InvalidOperationException("Resource of type `$type` not allowed without core extension.");
151 }
152
153 $messages = [];
154 $languages = [];
155 $language = ($profile ? $profile->getLanguage() : null) ?: Loc::getCurrentLang();
156 $isAllLangs = $profile ? $profile->isAllLangs() : false;
157 foreach ($assets as $asset)
158 {
160 $mess = $asset->useAllLangs($isAllLangs)->getContent();
161 if (!is_array($mess))
162 {
163 break;
164 }
165
166 if ($profile)
167 {
168 foreach ($mess as $messLanguage => $messList)
169 {
170 $messList = Resource\LangAsset::deletePrefixes(
171 $messList,
172 $profile->getDeleteLangPrefixes()
173 );
174 if ($profile->isLangCamelCase())
175 {
176 $messList = Resource\LangAsset::toCamelCase($messList);
177 }
178 if (!isset($messages[$messLanguage]) || !is_array($messages[$messLanguage]))
179 {
180 $messages[$messLanguage] = [];
181 }
182
183 $messages[$messLanguage] = array_merge(
184 $messages[$messLanguage],
185 $messList
186 );
187 }
188 }
189
190 $languages = array_unique(array_merge(
191 $languages,
192 array_keys($messages)
193 ));
194 }
195
196 if (count($messages) === 1)
197 {
198 $messages = current($messages);
199 }
200
202 $languages = JsonEncoder::encode($languages);
203 $content .= "module.language = \"$language\";" . self::getEol(1);
204 $content .= "module.languages = $languages;" . self::getEol(1);
205 $content .= "module.messages = $messages;" . self::getEol();
206
207 break;
208 }
209 }
210
211 return $content;
212 }
213
214 protected static function getEol($multiplier = 2)
215 {
216 return str_repeat("\n", $multiplier);
217 }
218
219 protected static function isCoreExtension($name)
220 {
221 return self::CORE_EXTENSION === $name;
222 }
223}
$type
Определения options.php:106
static getDefaultSiteUri()
Определения builder.php:288
static isCoreExtension($name)
Определения converter.php:219
static getEol($multiplier=2)
Определения converter.php:214
static encodeModule(Module $module)
Определения converter.php:71
static $hasCoreExtension
Определения converter.php:17
static wrap($content)
Определения converter.php:55
static stringify(Builder $builder)
Определения converter.php:25
static encode($data)
Определения jsonencoder.php:18
$content
Определения commerceml.php:144
$name
Определения menu_edit.php:35
</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
$messages
Определения template.php:8
$method
Определения index.php:27