1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
webpackbuilder.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Landing\Assets;
4
5
use Bitrix\Landing\Landing;
6
use Bitrix\Main;
7
11
class
WebpackBuilder
extends
Builder
12
{
13
protected
const
PACKAGE_CRITICAL_NAME
=
'landing_grid'
;
14
18
protected
ResourceCollection
$criticalResources
;
19
23
protected
array
$normalizedCriticalResources
= [];
24
28
protected
WebpackFile
$webpackFile
;
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
{
46
$this->
normalizeCriticalResources
();
47
$this->
normalizeBaseResources
();
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
90
$this->
fillPackageWithResources
();
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
$type
Определения
options.php:106
Bitrix\Landing\Assets\Location\LOCATION_BEFORE_ALL
const LOCATION_BEFORE_ALL
Определения
location.php:7
Bitrix\Landing\Assets\ResourceCollection
Определения
resourcecollection.php:13
Bitrix\Landing\Assets\Types\getAssetTypes
static getAssetTypes()
Определения
types.php:19
Bitrix\Landing\Assets\Types\TYPE_LANG
const TYPE_LANG
Определения
types.php:10
Bitrix\Landing\Assets\WebpackBuilder
Определения
webpackbuilder.php:12
Bitrix\Landing\Assets\WebpackBuilder\normalizeBaseResources
normalizeBaseResources()
Определения
webpackbuilder.php:56
Bitrix\Landing\Assets\WebpackBuilder\__construct
__construct(ResourceCollection $resources)
Определения
webpackbuilder.php:35
Bitrix\Landing\Assets\WebpackBuilder\normalizeCriticalResources
normalizeCriticalResources()
Определения
webpackbuilder.php:50
Bitrix\Landing\Assets\WebpackBuilder\PACKAGE_CRITICAL_NAME
const PACKAGE_CRITICAL_NAME
Определения
webpackbuilder.php:13
Bitrix\Landing\Assets\WebpackBuilder\fillPackageWithResources
fillPackageWithResources()
Определения
webpackbuilder.php:98
Bitrix\Landing\Assets\WebpackBuilder\normalizeResources
normalizeResources()
Определения
webpackbuilder.php:44
Bitrix\Landing\Assets\WebpackBuilder\$normalizedCriticalResources
array $normalizedCriticalResources
Определения
webpackbuilder.php:23
Bitrix\Landing\Assets\WebpackBuilder\createPackageHash
createPackageHash()
Определения
webpackbuilder.php:136
Bitrix\Landing\Assets\WebpackBuilder\$webpackFile
WebpackFile $webpackFile
Определения
webpackbuilder.php:28
Bitrix\Landing\Assets\WebpackBuilder\setCriticalOutput
setCriticalOutput()
Определения
webpackbuilder.php:119
Bitrix\Landing\Assets\WebpackBuilder\$criticalResources
ResourceCollection $criticalResources
Определения
webpackbuilder.php:18
Bitrix\Landing\Assets\WebpackBuilder\setOutput
setOutput()
Определения
webpackbuilder.php:65
Bitrix\Landing\Assets\WebpackBuilder\setBaseOutput
setBaseOutput()
Определения
webpackbuilder.php:127
Bitrix\Landing\Assets\WebpackBuilder\buildFile
buildFile()
Определения
webpackbuilder.php:84
Bitrix\Landing\Assets\WebpackFile
Определения
webpackfile.php:17
Bitrix\Main\ModuleManager\getVersion
static getVersion($moduleName)
Определения
modulemanager.php:89
Bitrix\Main\Web\WebPacker\Builder
Определения
builder.php:16
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
bitrix
modules
landing
lib
assets
webpackbuilder.php
Создано системой
1.14.0