1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
webpackbuilder.php
См. документацию.
1<?php
2
3namespace Bitrix\Landing\Assets;
4
5use Bitrix\Landing\Landing;
6use Bitrix\Main;
7
12{
13 protected const PACKAGE_CRITICAL_NAME = 'landing_grid';
14
19
24
29
35 public function __construct(ResourceCollection $resources)
36 {
37 parent::__construct($resources);
38 $this->criticalResources = new ResourceCollection();
39 }
40
44 protected function normalizeResources(): void
45 {
48 }
49
50 protected function normalizeCriticalResources(): void
51 {
52 $this->criticalResources = $this->resources->getSliceByLocation(Location::LOCATION_BEFORE_ALL);
53 $this->normalizedCriticalResources = $this->criticalResources->getNormalized();
54 }
55
56 protected function normalizeBaseResources(): void
57 {
58 $this->resources->remove($this->criticalResources->getPathes());
59 $this->normalizedResources = $this->resources->getNormalized();
60 }
61
65 public function setOutput(): void
66 {
67 if ($this->resources->isEmpty())
68 {
69 return;
70 }
71
72 $this->normalizeResources();
73
74 $this->buildFile();
75
76 $this->setCriticalOutput();
77 $this->setBaseOutput();
78 $this->setStrings();
79 }
80
84 protected function buildFile(): void
85 {
86 $this->webpackFile = new WebpackFile();
87 $this->webpackFile->setLandingId($this->landingId);
88 $this->webpackFile->setPackageHash($this->createPackageHash());
89
91
92 $this->webpackFile->build();
93 }
94
98 protected function fillPackageWithResources(): void
99 {
100 foreach (Types::getAssetTypes() as $type)
101 {
102 if (array_key_exists($type, $this->normalizedResources))
103 {
104 if($type === Types::TYPE_LANG)
105 {
106 $this->webpackFile->setUseLang();
107 }
108 foreach ($this->normalizedResources[$type] as $resource)
109 {
110 $this->webpackFile->addResource($resource);
111 }
112 }
113 }
114 }
115
119 protected function setCriticalOutput(): void
120 {
121 $this->initResourcesAsJsExtension($this->normalizedCriticalResources, self::PACKAGE_CRITICAL_NAME);
122 }
123
127 protected function setBaseOutput(): void
128 {
129 Main\Page\Asset::getInstance()->addString($this->webpackFile->getOutput());
130 }
131
136 protected function createPackageHash(): string
137 {
138 // List can be different with equal assets, because is depends on the order of adding assets. Unique and sort them!
139 $list = [];
140 foreach ($this->normalizedResources as $resources)
141 {
142 foreach ($resources as $resource)
143 {
144 $list[] = $resource;
145 }
146 }
147 $list = array_unique($list);
148 sort($list);
149
150 $list[] = 'version_' . Main\ModuleManager::getVersion('landing');
151 $list[] = 'lid_' . $this->landingId;
152 $list[] = Landing::getPreviewMode() ? 'previewMode' : 'publicMode';
153
154 return substr(md5(serialize($list)), 0, 10);
155 }
156}
$type
Определения options.php:106
const LOCATION_BEFORE_ALL
Определения location.php:7
static getAssetTypes()
Определения types.php:19
const TYPE_LANG
Определения types.php:10
__construct(ResourceCollection $resources)
Определения webpackbuilder.php:35
WebpackFile $webpackFile
Определения webpackbuilder.php:28
ResourceCollection $criticalResources
Определения webpackbuilder.php:18
static getVersion($moduleName)
Определения modulemanager.php:89
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804