Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
builder.php
1
<?php
2
3
namespace
Bitrix\Landing\Assets
;
4
5
use
Bitrix\Main\ArgumentException
;
6
use
Bitrix\Main\ArgumentTypeException
;
7
use
Bitrix\Main
;
8
9
10
abstract
class
Builder
11
{
12
protected
const
TYPE_STANDART
=
'STANDART'
;
13
protected
const
TYPE_WEBPACK
=
'WEBPACK'
;
14
15
protected
const
PACKAGE_NAME
=
'landing_assets'
;
16
20
protected
$resources
;
24
protected
$normalizedResources
= [];
29
protected
$landingId
= 0;
30
36
public
function
__construct
(
ResourceCollection
$resources
)
37
{
38
if
(
$resources
instanceof
ResourceCollection
)
39
{
40
$this->resources =
$resources
;
41
}
42
else
43
{
44
throw
new
ArgumentTypeException
(
$resources
,
'ResourceCollection'
);
45
}
46
}
47
55
public
static
function
createByType
(
ResourceCollection
$resources
,
string
$type): ?
Builder
56
{
57
switch
($type)
58
{
59
case
self::TYPE_STANDART
:
60
return
new
StandartBuilder
(
$resources
);
61
62
case
self::TYPE_WEBPACK
:
63
return
new
WebpackBuilder
(
$resources
);
64
65
default
:
66
throw
new
ArgumentException
(
"Unknown landing asset builder type `$type`."
);
67
}
68
}
69
74
public
function
attachToLanding
(
int
$lid): void
75
{
76
$this->landingId = (int)$lid;
77
}
78
83
abstract
public
function
setOutput
();
84
85
abstract
protected
function
normalizeResources
();
86
87
protected
function
initResourcesAsJsExtension
(array
$resources
, $extName =
null
): void
88
{
89
if
(!$extName)
90
{
91
$extName =
self::PACKAGE_NAME
;
92
}
93
$extFullName = $extName .
'_'
. md5(serialize(
$resources
));
94
95
$resources
= array_merge(
$resources
, [
96
'bundle_js'
=> $extFullName,
97
'bundle_css'
=> $extFullName,
98
'skip_core'
=>
true
,
99
]);
101
\CJSCore::registerExt($extName,
$resources
);
102
\CJSCore::Init($extName);
103
}
104
108
protected
function
setStrings
(): void
109
{
110
foreach
($this->resources->getStrings() as $string)
111
{
112
Main\Page\Asset::getInstance()->addString($string,
false
, Main\
Page
\AssetLocation::AFTER_JS);
113
}
114
}
115
}
Bitrix\Landing\Assets\Builder
Definition
builder.php:11
Bitrix\Landing\Assets\Builder\setStrings
setStrings()
Definition
builder.php:108
Bitrix\Landing\Assets\Builder\__construct
__construct(ResourceCollection $resources)
Definition
builder.php:36
Bitrix\Landing\Assets\Builder\normalizeResources
normalizeResources()
Bitrix\Landing\Assets\Builder\initResourcesAsJsExtension
initResourcesAsJsExtension(array $resources, $extName=null)
Definition
builder.php:87
Bitrix\Landing\Assets\Builder\PACKAGE_NAME
const PACKAGE_NAME
Definition
builder.php:15
Bitrix\Landing\Assets\Builder\$normalizedResources
$normalizedResources
Definition
builder.php:24
Bitrix\Landing\Assets\Builder\createByType
static createByType(ResourceCollection $resources, string $type)
Definition
builder.php:55
Bitrix\Landing\Assets\Builder\TYPE_WEBPACK
const TYPE_WEBPACK
Definition
builder.php:13
Bitrix\Landing\Assets\Builder\setOutput
setOutput()
Bitrix\Landing\Assets\Builder\TYPE_STANDART
const TYPE_STANDART
Definition
builder.php:12
Bitrix\Landing\Assets\Builder\$landingId
$landingId
Definition
builder.php:29
Bitrix\Landing\Assets\Builder\$resources
$resources
Definition
builder.php:20
Bitrix\Landing\Assets\Builder\attachToLanding
attachToLanding(int $lid)
Definition
builder.php:74
Bitrix\Landing\Assets\ResourceCollection
Definition
resourcecollection.php:13
Bitrix\Landing\Assets\StandartBuilder
Definition
standartbuilder.php:8
Bitrix\Landing\Assets\WebpackBuilder
Definition
webpackbuilder.php:9
Bitrix\Landing\Hook\Page
Definition
page.php:7
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\ArgumentTypeException
Definition
exception.php:114
Bitrix\Landing\Assets
Definition
builder.php:3
Bitrix\Main
modules
landing
lib
assets
builder.php
Создано системой
1.10.0