Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
loader.php
1
<?php
2
3
namespace
Bitrix\Main\Web\WebPacker
;
4
10
class
Loader
11
{
13
protected
$file
;
14
15
protected
$cacheTtl
= 60;
16
17
protected
$skipMoving
=
false
;
18
19
protected
$tagAttributes
= [];
20
26
public
function
__construct
(Output\
File
$file)
27
{
28
$this->file = $file;
29
}
30
37
public
function
setCacheTtl
($cacheTtl)
38
{
39
$this->cacheTtl = (int)
$cacheTtl
;
40
return
$this;
41
}
42
49
public
function
setSkipMoving
($skip)
50
{
51
$this->skipMoving = (bool) $skip;
52
return
$this;
53
}
54
61
public
function
setTagAttributes
(array $tagAttributes = [])
62
{
63
$this->tagAttributes =
$tagAttributes
;
64
return
$this;
65
}
66
72
public
function
getFileUrl
()
73
{
74
return
$this->file->getUri();
75
}
76
82
public
function
getString
()
83
{
84
$content = $this->
getStringJs
();
85
$attributes = $this->tagAttributes;
86
if
($this->skipMoving)
87
{
88
$attributes[
'data-skip-moving'
] =
'true'
;
89
}
90
$attrs =
''
;
91
foreach
($attributes as $key => $value)
92
{
93
$attrs .=
" "
. htmlspecialcharsbx($key) .
'="'
94
. htmlspecialcharsbx($value) .
'"'
;
95
}
96
return
<<<EOD
97
<script{$attrs}>
98
$content
99
</script>
100
EOD;
101
102
}
103
109
public
function
getStringJs
()
110
{
111
$path = $this->file->getUri();
112
if
(!$path)
113
{
114
return
''
;
115
}
116
117
$ttl = ($this->cacheTtl ?: 1) * 1000;
118
119
return
120
<<<EOD
121
(
function
(w,d,u){
122
var s=d.createElement(
'script'
);s.async=
true
;s.src=u+
'?'
+(
Date
.now()/$ttl|0);
123
var h=d.getElementsByTagName(
'script'
)[0];h.parentNode.insertBefore(s,h);
124
})(window,document,
'$path'
);
125
EOD;
126
127
}
128
}
Bitrix\Main\IO\File
Definition
file.php:7
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Type\Date
Definition
date.php:9
Bitrix\Main\Web\WebPacker\Loader\__construct
__construct(Output\File $file)
Definition
loader.php:26
Bitrix\Main\Web\WebPacker\Loader\setCacheTtl
setCacheTtl($cacheTtl)
Definition
loader.php:37
Bitrix\Main\Web\WebPacker\Loader\setSkipMoving
setSkipMoving($skip)
Definition
loader.php:49
Bitrix\Main\Web\WebPacker\Loader\$skipMoving
$skipMoving
Definition
loader.php:17
Bitrix\Main\Web\WebPacker\Loader\getStringJs
getStringJs()
Definition
loader.php:109
Bitrix\Main\Web\WebPacker\Loader\$file
$file
Definition
loader.php:13
Bitrix\Main\Web\WebPacker\Loader\$cacheTtl
$cacheTtl
Definition
loader.php:15
Bitrix\Main\Web\WebPacker\Loader\setTagAttributes
setTagAttributes(array $tagAttributes=[])
Definition
loader.php:61
Bitrix\Main\Web\WebPacker\Loader\getFileUrl
getFileUrl()
Definition
loader.php:72
Bitrix\Main\Web\WebPacker\Loader\$tagAttributes
$tagAttributes
Definition
loader.php:19
Bitrix\Main\Web\WebPacker\Loader\getString
getString()
Definition
loader.php:82
Bitrix\Main\Web\WebPacker
Definition
builder.php:3
modules
main
lib
web
webpacker
loader.php
Создано системой
1.10.0