1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
filestorage.php
См. документацию.
1
<?php
2
namespace
Bitrix\Main\Composite\Data;
3
4
use Bitrix\Main;
5
use Bitrix\Main\IO\File;
6
7
final
class
FileStorage
extends
AbstractStorage
8
{
9
private
$cacheFile =
null
;
10
11
function
__construct
(
$cacheKey
,
array
$configuration
,
array
$htmlCacheOptions
)
12
{
13
parent::__construct(
$cacheKey
,
$configuration
,
$htmlCacheOptions
);
14
15
$this->cacheFile =
new
Main\IO\File
(
Main
\
IO
\Path::convertRelativeToAbsolute(
16
Main
\
Application::getPersonalRoot
()
17
.
"/html_pages"
18
.$this->cacheKey
19
));
20
}
21
22
public
function
write
(
$content
,
$md5
)
23
{
24
$written =
false
;
25
26
if
($this->cacheFile)
27
{
28
$tempFile =
new
File
($this->cacheFile->getPhysicalPath().
".tmp"
);
29
30
try
31
{
32
$written = $tempFile->putContents(
$content
);
33
$this->cacheFile->delete();
34
if
(!$tempFile->rename($this->cacheFile->getPhysicalPath()))
35
{
36
$written =
false
;
37
}
38
}
39
catch
(\Exception $exception)
40
{
41
$written =
false
;
42
$this->cacheFile->delete();
43
$tempFile->delete();
44
}
45
}
46
47
return
$written;
48
}
49
50
public
function
read
()
51
{
52
if
($this->
exists
())
53
{
54
try
55
{
56
return
$this->cacheFile->getContents();
57
}
58
catch
(\Exception $exception)
59
{
60
61
}
62
}
63
64
return
false
;
65
}
66
67
public
function
exists
()
68
{
69
if
($this->cacheFile)
70
{
71
return
$this->cacheFile->isExists();
72
}
73
else
74
{
75
return
false
;
76
}
77
}
78
79
public
function
delete
()
80
{
81
$fileSize =
false
;
82
if
($this->cacheFile && $this->cacheFile->isExists())
83
{
84
try
85
{
86
$cacheDirectory = $this->cacheFile->getDirectory();
87
$fileSize = $this->cacheFile->getSize();
88
$this->cacheFile->delete();
89
90
//Try to cleanup directory
91
$children
= $cacheDirectory->getChildren();
92
if
(empty(
$children
))
93
{
94
$cacheDirectory->delete();
95
}
96
}
97
catch
(\Exception $exception)
98
{
99
100
}
101
}
102
103
return
$fileSize;
104
}
105
106
public
function
deleteAll
()
107
{
108
return
(
bool
)
self::deleteRecursive
(
"/"
);
109
}
110
111
public
function
getMd5
()
112
{
113
if
($this->
exists
())
114
{
115
$content
= $this->
read
();
116
return
$content
!==
false
? mb_substr(
$content
, -35, 32) :
false
;
117
}
118
119
return
false
;
120
}
121
126
public
function
shouldCountQuota
()
127
{
128
return
true
;
129
}
130
131
public
function
getLastModified
()
132
{
133
if
($this->
exists
())
134
{
135
try
136
{
137
return
$this->cacheFile->getModificationTime();
138
}
139
catch
(\Exception $exception)
140
{
141
142
}
143
}
144
145
return
false
;
146
}
147
152
public
function
getSize
()
153
{
154
if
($this->cacheFile && $this->cacheFile->isExists())
155
{
156
try
157
{
158
return
$this->cacheFile->getSize();
159
}
160
catch
(\Exception $exception)
161
{
162
163
}
164
}
165
166
return
false
;
167
}
168
169
public
function
getCacheFile
()
170
{
171
return
$this->cacheFile;
172
}
173
180
public
static
function
deleteRecursive
($relativePath =
""
,
$validTime
= 0)
181
{
182
$bytes
= 0.0;
183
if
(str_contains($relativePath,
".."
))
184
{
185
return
$bytes
;
186
}
187
188
$relativePath = rtrim($relativePath,
"/"
);
189
$baseDir =
$_SERVER
[
"DOCUMENT_ROOT"
].BX_PERSONAL_ROOT.
"/html_pages"
;
190
$absPath = $baseDir.$relativePath;
191
192
if
(is_file($absPath))
193
{
194
if
(
195
(
$validTime
&& filemtime($absPath) >
$validTime
) ||
196
in_array($relativePath,
array
(
"/.enabled"
,
"/.config.php"
,
"/.htaccess"
,
"/.size"
,
"/404.php"
)))
197
{
198
return
$bytes
;
199
}
200
201
$bytes
= filesize($absPath);
202
@unlink($absPath);
203
return
doubleval(
$bytes
);
204
}
205
elseif
(is_dir($absPath) && (
$handle
= opendir($absPath)) !==
false
)
206
{
207
while
(($file = readdir(
$handle
)) !==
false
)
208
{
209
if
($file ===
"."
|| $file ===
".."
)
210
{
211
continue
;
212
}
213
214
$bytes
+=
self::deleteRecursive
($relativePath.
"/"
.$file,
$validTime
);
215
}
216
closedir(
$handle
);
217
218
if
($baseDir !== $absPath)
219
{
220
@rmdir($absPath);
221
}
222
}
223
224
return
doubleval(
$bytes
);
225
}
226
}
227
228
class_alias(
"Bitrix\\Main\\Composite\\Data\\FileStorage"
,
"Bitrix\\Main\\Data\\StaticHtmlFileStorage"
);
Bitrix\Main\Application\getPersonalRoot
static getPersonalRoot()
Определения
application.php:762
Bitrix\Main\Composite\Data\AbstractStorage
Определения
abstractstorage.php:10
Bitrix\Main\Composite\Data\AbstractStorage\$cacheKey
$cacheKey
Определения
abstractstorage.php:11
Bitrix\Main\Composite\Data\AbstractStorage\$htmlCacheOptions
$htmlCacheOptions
Определения
abstractstorage.php:13
Bitrix\Main\Composite\Data\AbstractStorage\$configuration
$configuration
Определения
abstractstorage.php:12
Bitrix\Main\Composite\Data\FileStorage
Определения
filestorage.php:8
Bitrix\Main\Composite\Data\FileStorage\getCacheFile
getCacheFile()
Определения
filestorage.php:169
Bitrix\Main\Composite\Data\FileStorage\deleteRecursive
static deleteRecursive($relativePath="", $validTime=0)
Определения
filestorage.php:180
Bitrix\Main\Composite\Data\FileStorage\read
read()
Определения
filestorage.php:50
Bitrix\Main\Composite\Data\FileStorage\__construct
__construct($cacheKey, array $configuration, array $htmlCacheOptions)
Определения
filestorage.php:11
Bitrix\Main\Composite\Data\FileStorage\getSize
getSize()
Определения
filestorage.php:152
Bitrix\Main\Composite\Data\FileStorage\getMd5
getMd5()
Определения
filestorage.php:111
Bitrix\Main\Composite\Data\FileStorage\write
write($content, $md5)
Определения
filestorage.php:22
Bitrix\Main\Composite\Data\FileStorage\getLastModified
getLastModified()
Определения
filestorage.php:131
Bitrix\Main\Composite\Data\FileStorage\deleteAll
deleteAll()
Определения
filestorage.php:106
Bitrix\Main\Composite\Data\FileStorage\exists
exists()
Определения
filestorage.php:67
Bitrix\Main\Composite\Data\FileStorage\shouldCountQuota
shouldCountQuota()
Определения
filestorage.php:126
$children
$children
Определения
sync.php:12
$content
$content
Определения
commerceml.php:144
$bytes
$bytes
Определения
cron_html_pages.php:17
$validTime
$validTime
Определения
cron_html_pages.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
$handle
$handle
Определения
include.php:55
$_SERVER
$_SERVER["DOCUMENT_ROOT"]
Определения
cron_frame.php:9
Bitrix\Main\File
Определения
Image.php:9
Bitrix\Main\IO
Определения
directory.php:3
Bitrix\Main
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$md5
$md5
Определения
result_rec.php:12
bitrix
modules
main
lib
composite
data
filestorage.php
Создано системой
1.14.0