Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
archive.php
1
<?php
2
namespace
Bitrix\Main\Engine\Response\Zip
;
3
4
use
Bitrix\Main\HttpResponse
;
5
use
Bitrix\Main\Text\Encoding
;
6
use
Bitrix\Main\Web\Uri
;
7
8
class
Archive
extends
HttpResponse
9
{
10
public
const
MOD_ZIP_HEADER_NAME
=
'X-Archive-Files'
;
15
protected
string
$name
;
16
21
protected
array
$entries
= [];
22
27
public
function
__construct
(
string
$name
)
28
{
29
parent::__construct();
30
31
$this->name =
$name
;
32
$this->
addHeader
(self::MOD_ZIP_HEADER_NAME,
'zip'
);
33
}
34
39
public
function
addEntry
($archiveEntry): void
40
{
41
if
($archiveEntry instanceof
ArchiveEntry
)
42
{
43
$this->entries[] = $archiveEntry;
44
}
45
elseif ($archiveEntry instanceof
EntryInterface
)
46
{
47
$this->entries[] = $archiveEntry;
48
}
49
}
50
51
private
function
convertEntryInterfaceToString(
EntryInterface
$entry): string
52
{
53
$crc32 = ($entry->
getCrc32
() !==
''
) ? $entry->
getCrc32
() :
'-'
;
54
$name
= Encoding::convertEncoding(
55
$entry->
getPath
(),
56
LANG_CHARSET,
57
'UTF-8'
58
);
59
60
return
"{$crc32} {$entry->getSize()} {$entry->getServerRelativeUrl()} {$name}"
;
61
}
62
67
public
function
isEmpty
(): bool
68
{
69
return
empty($this->entries);
70
}
71
76
protected
function
getFileList
(): string
77
{
78
$list = [];
79
foreach
($this->entries as $entry)
80
{
81
if
($entry instanceof
ArchiveEntry
)
82
{
83
$list[] = (string)$entry;
84
}
85
elseif ($entry instanceof
EntryInterface
)
86
{
87
$list[] = $this->convertEntryInterfaceToString($entry);
88
}
89
}
90
91
return
implode(
"\n"
, $list);
92
}
93
94
protected
function
setContentDispositionHeader
(): void
95
{
96
$utfName = Uri::urnEncode($this->name,
'UTF-8'
);
97
$translitName = \CUtil::translit($this->name, LANGUAGE_ID, [
98
'max_len'
=> 1024,
99
'safe_chars'
=>
'.'
,
100
'replace_space'
=>
'-'
,
101
]);
102
$this->
addHeader
(
103
'Content-Disposition'
,
104
"attachment; filename=\"{$translitName}\"; filename*=utf-8''{$utfName}"
105
);
106
}
107
108
public
function
send
(): void
109
{
110
if
(!$this->
isEmpty
())
111
{
112
$this->
setContentDispositionHeader
();
113
$this->
setContent
(
114
$this->
getFileList
()
115
);
116
}
117
118
parent::send();
119
}
120
}
Bitrix\Main\Engine\Response\Zip\ArchiveEntry
Definition
archiveentry.php:15
Bitrix\Main\Engine\Response\Zip\Archive
Definition
archive.php:9
Bitrix\Main\Engine\Response\Zip\Archive\addEntry
addEntry($archiveEntry)
Definition
archive.php:39
Bitrix\Main\Engine\Response\Zip\Archive\$entries
array $entries
Definition
archive.php:21
Bitrix\Main\Engine\Response\Zip\Archive\send
send()
Definition
archive.php:108
Bitrix\Main\Engine\Response\Zip\Archive\__construct
__construct(string $name)
Definition
archive.php:27
Bitrix\Main\Engine\Response\Zip\Archive\MOD_ZIP_HEADER_NAME
const MOD_ZIP_HEADER_NAME
Definition
archive.php:10
Bitrix\Main\Engine\Response\Zip\Archive\getFileList
getFileList()
Definition
archive.php:76
Bitrix\Main\Engine\Response\Zip\Archive\$name
string $name
Definition
archive.php:15
Bitrix\Main\Engine\Response\Zip\Archive\setContentDispositionHeader
setContentDispositionHeader()
Definition
archive.php:94
Bitrix\Main\Engine\Response\Zip\Archive\isEmpty
isEmpty()
Definition
archive.php:67
Bitrix\Main\HttpResponse
Definition
httpresponse.php:8
Bitrix\Main\HttpResponse\addHeader
addHeader($name, $value='')
Definition
httpresponse.php:72
Bitrix\Main\Response\setContent
setContent($content)
Definition
response.php:31
Bitrix\Main\Text\Encoding
Definition
encoding.php:8
Bitrix\Main\Web\Uri
Definition
uri.php:17
Bitrix\Main\Engine\Response\Zip\EntryInterface
Definition
entryinterface.php:6
Bitrix\Main\Engine\Response\Zip\EntryInterface\getPath
getPath()
Bitrix\Main\Engine\Response\Zip\EntryInterface\getCrc32
getCrc32()
Bitrix\Main\Engine\Response\Zip
Definition
archive.php:2
modules
main
lib
engine
response
zip
archive.php
Создано системой
1.10.0