Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
webpackbuilder.php
1<?php
2
4
7
9{
10 protected const PACKAGE_CRITICAL_NAME = 'landing_grid';
11
20
24 protected $webpackFile;
25
32 {
33 parent::__construct($resources);
34 $this->criticalResources = new ResourceCollection();
35 }
36
40 protected function normalizeResources(): void
41 {
44 }
45
46 // todo: normalize lang in critical (like standartbuilder)
47 protected function normalizeCriticalResources(): void
48 {
49 $this->criticalResources = $this->resources->getSliceByLocation(Location::LOCATION_BEFORE_ALL);
50 $this->normalizedCriticalResources = $this->criticalResources->getNormalized();
51 }
52
53 protected function normalizeBaseResources(): void
54 {
55 $this->resources->remove($this->criticalResources->getPathes());
56 $this->normalizedResources = $this->resources->getNormalized();
57 }
58
62 public function setOutput(): void
63 {
64 if ($this->resources->isEmpty())
65 {
66 return;
67 }
68
69 $this->normalizeResources();
70
71 $this->buildFile();
72
73 $this->setCriticalOutput();
74 $this->setBaseOutput();
75 $this->setStrings();
76 }
77
81 protected function buildFile(): void
82 {
83 $this->webpackFile = new WebpackFile();
84 $this->webpackFile->setLandingId($this->landingId);
85 $this->webpackFile->setPackageHash($this->createPackageHash());
86
88
89 $this->webpackFile->build();
90 }
91
95 protected function fillPackageWithResources(): void
96 {
97 foreach (Types::getAssetTypes() as $type)
98 {
99 if (array_key_exists($type, $this->normalizedResources))
100 {
101 if($type === Types::TYPE_LANG)
102 {
103 $this->webpackFile->setUseLang();
104 }
105 foreach ($this->normalizedResources[$type] as $resource)
106 {
107 $this->webpackFile->addResource($resource);
108 }
109 }
110 }
111 }
112
116 protected function setCriticalOutput(): void
117 {
118 $this->initResourcesAsJsExtension($this->normalizedCriticalResources, self::PACKAGE_CRITICAL_NAME);
119 }
120
124 protected function setBaseOutput(): void
125 {
126 Main\Page\Asset::getInstance()->addString($this->webpackFile->getOutput());
127 }
128
133 protected function createPackageHash(): string
134 {
135 // List can be different with equal assets, because is depends on the order of adding assets. Unique and sort them!
136 $list = [];
137 foreach ($this->normalizedResources as $type => $resources)
138 {
139 foreach ($resources as $resource)
140 {
141 $list[] = $resource;
142 }
143 }
144 $list = array_unique($list);
145 sort($list);
146
147 $list[] = 'version_' . Main\ModuleManager::getVersion('landing');
148 $list[] = 'lid_' . $this->landingId;
149 $list[] = Landing::getPreviewMode() ? 'previewMode' : 'publicMode';
150
151 return substr(md5(serialize($list)), 0, 10);
152 }
153}
initResourcesAsJsExtension(array $resources, $extName=null)
Definition builder.php:87
__construct(ResourceCollection $resources)