1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
file.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Main\Web\WebPacker\Output;
4
5
use Bitrix\Main\Config\Option;
6
use Bitrix\Main\Error;
7
use Bitrix\Main\SystemException;
8
use Bitrix\Main\Web\WebPacker;
9
use Bitrix\Main\Web\MimeType;
10
16
class
File
extends
Base
17
{
18
protected
?
int
$id
=
null
;
19
protected
$moduleId
;
20
protected
$uploadDir
;
21
protected
$dir
;
22
protected
$name
;
23
protected
$type
;
24
protected
$content
;
25
32
public
static
function
removeById
(
$id
)
33
{
34
\CFile::Delete(
$id
);
35
}
36
43
public
function
output
(
WebPacker
\
Builder
$builder)
44
{
45
if
(!$this->moduleId)
46
{
47
throw
new
SystemException
(
'Module ID is empty.'
);
48
}
49
if
(!$this->name)
50
{
51
throw
new
SystemException
(
'File name is empty.'
);
52
}
53
54
$content
= $builder->stringify();
55
$id
= $this->
saveFile
(
$content
);
56
57
$result
= (
new
Result
())->
setId
(
$id
)->setContent(
$content
);
58
if
(!
$id
)
59
{
60
$result
->addError(
new
Error
(
'Empty file ID.'
));
61
}
62
63
return
$result
;
64
}
65
72
public
function
setContent
(
$content
)
73
{
74
$this->content =
$content
;
75
return
$this;
76
}
77
84
public
function
setId
(?
int
$id
): static
85
{
86
$this->
id
= $id;
87
88
return
$this;
89
}
90
96
public
function
getId
(): ?int
97
{
98
return
$this->id;
99
}
100
107
public
function
setModuleId
(
$moduleId
)
108
{
109
$this->moduleId =
$moduleId
;
110
return
$this;
111
}
112
119
public
function
setUploadDir
(
$uploadDir
)
120
{
121
$this->uploadDir =
$uploadDir
;
122
return
$this;
123
}
124
131
public
function
setDir
(
$dir
)
132
{
133
$this->dir =
$dir
;
134
return
$this;
135
}
136
143
public
function
setName
(
$name
)
144
{
145
$this->name =
$name
;
146
return
$this;
147
}
148
155
public
function
setType
(
$type
)
156
{
157
$this->type =
$type
;
158
return
$this;
159
}
160
166
public
function
remove
()
167
{
168
if
(!$this->
id
)
169
{
170
return
;
171
}
172
173
static::removeById($this->
id
);
174
}
175
181
public
function
getUri
()
182
{
183
$uri
=
''
;
184
if
(!$this->
id
)
185
{
186
return
$uri
;
187
}
188
189
$file = \CFile::GetFileArray($this->
id
);
190
if
(!$file)
191
{
192
return
$uri
;
193
}
194
195
$uri
= $file[
'SRC'
];
196
if
(
$uri
&& !preg_match(
'#^(https?://)#'
,
$uri
))
197
{
198
return
WebPacker\Builder::getDefaultSiteUri
() .
$uri
;
199
}
200
201
if
(
$uri
)
202
{
203
return
$uri
;
204
}
205
206
$uploadDir
= $this->uploadDir ?: Option::get(
"main"
,
"upload_dir"
,
"upload"
);
207
return
WebPacker\Builder::getDefaultSiteUri
() .
208
'/'
.
$uploadDir
.
209
'/'
. $file[
'SUBDIR'
] .
210
'/'
. $file[
'FILE_NAME'
]
211
;
212
}
213
214
protected
function
saveFile
(
$content
)
215
{
216
$this->
remove
();
217
218
$type
=
$this->type
;
219
if
(!
$type
&& $this->name)
220
{
221
$type
= static::getMimeTypeByFileName($this->name);
222
}
223
224
$fileArray = [
225
'MODULE_ID'
=>
$this->moduleId
,
226
'name'
=>
$this->name
,
227
'content'
=>
$content
228
];
229
230
if
(
$type
)
231
{
232
$fileArray[
'type'
] =
$type
;
233
}
234
235
$this->
id
= \CFile::SaveFile(
236
$fileArray,
237
$this->moduleId,
238
false
,
239
false
,
240
$this->dir ?:
''
241
);
242
243
return
$this->id;
244
}
245
246
protected
static
function
getMimeTypeByFileName
(
$fileName
)
247
{
248
$extension = mb_strtolower(getFileExtension(
$fileName
));
249
$list =
MimeType::getMimeTypeList
();
250
if
(isset($list[$extension]))
251
{
252
return
$list[$extension];
253
}
254
255
return
'text/plain'
;
256
}
257
}
$type
$type
Определения
options.php:106
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\ORM\Data\Result
Определения
result.php:16
Bitrix\Main\SystemException
Определения
SystemException.php:9
Bitrix\Main\Web\MimeType\getMimeTypeList
static getMimeTypeList()
Определения
mimetype.php:235
Bitrix\Main\Web\WebPacker\Builder
Определения
builder.php:16
Bitrix\Main\Web\WebPacker\Builder\getDefaultSiteUri
static getDefaultSiteUri()
Определения
builder.php:288
Bitrix\Main\Web\WebPacker\Output\Base
Определения
base.php:13
Bitrix\Main\Web\WebPacker\Output\File\setId
setId(?int $id)
Определения
file.php:84
Bitrix\Main\Web\WebPacker\Output\File\setContent
setContent($content)
Определения
file.php:72
Bitrix\Main\Web\WebPacker\Output\File\getId
getId()
Определения
file.php:96
Bitrix\Main\Web\WebPacker\Output\File\$dir
$dir
Определения
file.php:21
Bitrix\Main\Web\WebPacker\Output\File\saveFile
saveFile($content)
Определения
file.php:214
Bitrix\Main\Web\WebPacker\Output\File\output
output(WebPacker\Builder $builder)
Определения
file.php:43
Bitrix\Main\Web\WebPacker\Output\File\getUri
getUri()
Определения
file.php:181
Bitrix\Main\Web\WebPacker\Output\File\setUploadDir
setUploadDir($uploadDir)
Определения
file.php:119
Bitrix\Main\Web\WebPacker\Output\File\setName
setName($name)
Определения
file.php:143
Bitrix\Main\Web\WebPacker\Output\File\$id
int $id
Определения
file.php:18
Bitrix\Main\Web\WebPacker\Output\File\setDir
setDir($dir)
Определения
file.php:131
Bitrix\Main\Web\WebPacker\Output\File\$content
$content
Определения
file.php:24
Bitrix\Main\Web\WebPacker\Output\File\getMimeTypeByFileName
static getMimeTypeByFileName($fileName)
Определения
file.php:246
Bitrix\Main\Web\WebPacker\Output\File\setModuleId
setModuleId($moduleId)
Определения
file.php:107
Bitrix\Main\Web\WebPacker\Output\File\$uploadDir
$uploadDir
Определения
file.php:20
Bitrix\Main\Web\WebPacker\Output\File\$type
$type
Определения
file.php:23
Bitrix\Main\Web\WebPacker\Output\File\$name
$name
Определения
file.php:22
Bitrix\Main\Web\WebPacker\Output\File\removeById
static removeById($id)
Определения
file.php:32
Bitrix\Main\Web\WebPacker\Output\File\$moduleId
$moduleId
Определения
file.php:19
Bitrix\Main\Web\WebPacker\Output\File\setType
setType($type)
Определения
file.php:155
$result
$result
Определения
get_property_values.php:14
$moduleId
$moduleId
Определения
group_bizproc_workflow_delete.php:16
$uri
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения
urlrewrite.php:61
$name
$name
Определения
menu_edit.php:35
Bitrix\Main\File
Определения
Image.php:9
Bitrix\Main\Web\WebPacker
Определения
builder.php:3
$fileName
$fileName
Определения
quickway.php:305
bitrix
modules
main
lib
web
webpacker
output
file.php
Создано системой
1.14.0