1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
archive.php
См. документацию.
1
<?php
2
namespace
Bitrix\Main\Engine\Response\Zip
;
3
4
use
Bitrix\Main\HttpResponse
;
5
use
Bitrix\Main\Web\Uri
;
6
7
class
Archive
extends
HttpResponse
8
{
9
public
const
MOD_ZIP_HEADER_NAME
=
'X-Archive-Files'
;
14
protected
string
$name
;
15
20
protected
array
$entries
= [];
21
26
public
function
__construct
(
string
$name
)
27
{
28
parent::__construct();
29
30
$this->name =
$name
;
31
$this->
addHeader
(self::MOD_ZIP_HEADER_NAME,
'zip'
);
32
}
33
38
public
function
addEntry
($archiveEntry): void
39
{
40
if
($archiveEntry instanceof
ArchiveEntry
)
41
{
42
$this->entries[] = $archiveEntry;
43
}
44
elseif
($archiveEntry instanceof
EntryInterface
)
45
{
46
$this->entries[] = $archiveEntry;
47
}
48
}
49
50
private
function
convertEntryInterfaceToString(
EntryInterface
$entry): string
51
{
52
$crc32 = ($entry->
getCrc32
() !==
''
) ? $entry->
getCrc32
() :
'-'
;
53
$name
= $entry->
getPath
();
54
55
return
"{$crc32} {$entry->getSize()} {$entry->getServerRelativeUrl()} {$name}"
;
56
}
57
62
public
function
isEmpty
(): bool
63
{
64
return
empty($this->entries);
65
}
66
71
protected
function
getFileList
(): string
72
{
73
$list = [];
74
foreach
($this->entries as $entry)
75
{
76
if
($entry instanceof
ArchiveEntry
)
77
{
78
$list[] = (string)$entry;
79
}
80
elseif
($entry instanceof
EntryInterface
)
81
{
82
$list[] = $this->convertEntryInterfaceToString($entry);
83
}
84
}
85
86
return
implode(
"\n"
, $list);
87
}
88
89
protected
function
setContentDispositionHeader
(): void
90
{
91
$utfName = Uri::urnEncode($this->name,
'UTF-8'
);
92
$translitName = \CUtil::translit($this->name, LANGUAGE_ID, [
93
'max_len'
=> 1024,
94
'safe_chars'
=>
'.'
,
95
'replace_space'
=>
'-'
,
96
]);
97
$this->
addHeader
(
98
'Content-Disposition'
,
99
"attachment; filename=\"{$translitName}\"; filename*=utf-8''{$utfName}"
100
);
101
}
102
103
public
function
send
(): void
104
{
105
if
(!$this->
isEmpty
())
106
{
107
$this->
setContentDispositionHeader
();
108
$this->
setContent
(
109
$this->
getFileList
()
110
);
111
}
112
113
parent::send();
114
}
115
}
Bitrix\Main\Engine\Response\Zip\ArchiveEntry
Определения
archiveentry.php:14
Bitrix\Main\Engine\Response\Zip\Archive
Определения
archive.php:8
Bitrix\Main\Engine\Response\Zip\Archive\addEntry
addEntry($archiveEntry)
Определения
archive.php:38
Bitrix\Main\Engine\Response\Zip\Archive\$entries
array $entries
Определения
archive.php:20
Bitrix\Main\Engine\Response\Zip\Archive\send
send()
Определения
archive.php:103
Bitrix\Main\Engine\Response\Zip\Archive\__construct
__construct(string $name)
Определения
archive.php:26
Bitrix\Main\Engine\Response\Zip\Archive\MOD_ZIP_HEADER_NAME
const MOD_ZIP_HEADER_NAME
Определения
archive.php:9
Bitrix\Main\Engine\Response\Zip\Archive\getFileList
getFileList()
Определения
archive.php:71
Bitrix\Main\Engine\Response\Zip\Archive\$name
string $name
Определения
archive.php:14
Bitrix\Main\Engine\Response\Zip\Archive\setContentDispositionHeader
setContentDispositionHeader()
Определения
archive.php:89
Bitrix\Main\Engine\Response\Zip\Archive\isEmpty
isEmpty()
Определения
archive.php:62
Bitrix\Main\HttpResponse
Определения
httpresponse.php:8
Bitrix\Main\HttpResponse\addHeader
addHeader($name, $value='')
Определения
httpresponse.php:72
Bitrix\Main\Response\setContent
setContent($content)
Определения
response.php:31
Bitrix\Main\Web\Uri
Определения
uri.php:17
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\Main\Engine\Response\Zip\EntryInterface
Определения
entryinterface.php:6
Bitrix\Main\Engine\Response\Zip\EntryInterface\getPath
getPath()
Bitrix\Main\Engine\Response\Zip\EntryInterface\getCrc32
getCrc32()
$name
$name
Определения
menu_edit.php:35
Bitrix\Main\Engine\Response\Zip
Определения
archive.php:2
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
bitrix
modules
main
lib
engine
response
zip
archive.php
Создано системой
1.14.0