Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
UploaderError.php
1<?php
2
4
6
7Loc::loadLanguageFile(__DIR__ . '/UserErrors.php');
8
10{
11 protected string $description = '';
12 protected bool $system = false;
13
14 public const MAX_FILE_SIZE_EXCEEDED = 'MAX_FILE_SIZE_EXCEEDED';
15 public const MIN_FILE_SIZE_EXCEEDED = 'MIN_FILE_SIZE_EXCEEDED';
16 public const FILE_TYPE_NOT_ALLOWED = 'FILE_TYPE_NOT_ALLOWED';
17 public const FILE_NAME_NOT_ALLOWED = 'FILE_NAME_NOT_ALLOWED';
18 public const IMAGE_MAX_FILE_SIZE_EXCEEDED = 'IMAGE_MAX_FILE_SIZE_EXCEEDED';
19 public const IMAGE_MIN_FILE_SIZE_EXCEEDED = 'IMAGE_MIN_FILE_SIZE_EXCEEDED';
20 public const IMAGE_TYPE_NOT_SUPPORTED = 'IMAGE_TYPE_NOT_SUPPORTED';
21 public const IMAGE_IS_TOO_SMALL = 'IMAGE_IS_TOO_SMALL';
22 public const IMAGE_IS_TOO_BIG = 'IMAGE_IS_TOO_BIG';
23
24 public const SAVE_FILE_FAILED = 'SAVE_FILE_FAILED';
25 public const FILE_LOAD_FAILED = 'FILE_LOAD_FAILED';
26 public const FILE_UPLOAD_ACCESS_DENIED = 'FILE_UPLOAD_ACCESS_DENIED';
27 public const FILE_LOAD_ACCESS_DENIED = 'FILE_LOAD_ACCESS_DENIED';
28 public const FILE_REMOVE_ACCESS_DENIED = 'FILE_REMOVE_ACCESS_DENIED';
29
30 public const INVALID_CONTENT_RANGE = 'INVALID_CONTENT_RANGE';
31 public const INVALID_CONTENT_TYPE = 'INVALID_CONTENT_TYPE';
32 public const INVALID_CONTENT_LENGTH = 'INVALID_CONTENT_LENGTH';
33 public const INVALID_CONTENT_NAME = 'INVALID_CONTENT_NAME';
34 public const INVALID_FILENAME = 'INVALID_FILENAME';
35 public const INVALID_RANGE_SIZE = 'INVALID_RANGE_SIZE';
36 public const INVALID_CHUNK_SIZE = 'INVALID_CHUNK_SIZE';
37 public const INVALID_CHUNK_OFFSET = 'INVALID_CHUNK_OFFSET';
38 public const TOO_BIG_REQUEST = 'TOO_BIG_REQUEST';
39 public const FILE_FIND_FAILED = 'FILE_FIND_FAILED';
40 public const FILE_MOVE_FAILED = 'FILE_MOVE_FAILED';
41 public const FILE_APPEND_NOT_FOUND = 'FILE_APPEND_NOT_FOUND';
42 public const CHUNK_NOT_FOUND = 'CHUNK_NOT_FOUND';
43 public const CHUNK_COPY_FAILED = 'CHUNK_COPY_FAILED';
44 public const CHUNK_TOO_BIG = 'CHUNK_TOO_BIG';
45 public const CHUNK_APPEND_NOT_FOUND = 'CHUNK_APPEND_NOT_FOUND';
46 public const CHUNK_APPEND_FAILED = 'CHUNK_APPEND_FAILED';
47 public const CLOUD_EMPTY_BUCKET = 'CLOUD_EMPTY_BUCKET';
48 public const CLOUD_INVALID_CHUNK_SIZE = 'CLOUD_INVALID_CHUNK_SIZE';
49 public const CLOUD_GET_CONTENTS_FAILED = 'CLOUD_GET_CONTENTS_FAILED';
50 public const CLOUD_START_UPLOAD_FAILED = 'CLOUD_START_UPLOAD_FAILED';
51 public const CLOUD_FINISH_UPLOAD_FAILED = 'CLOUD_FINISH_UPLOAD_FAILED';
52 public const CLOUD_UPLOAD_FAILED = 'CLOUD_UPLOAD_FAILED';
53 public const EMPTY_TOKEN = 'EMPTY_TOKEN';
54 public const UNKNOWN_TOKEN = 'UNKNOWN_TOKEN';
55 public const INVALID_SIGNATURE = 'INVALID_SIGNATURE';
56
57 private static array $systemErrors = [
58 self::INVALID_CONTENT_RANGE => 'Content-Range header is invalid',
59 self::INVALID_CONTENT_TYPE => 'Content-Type header is required.',
60 self::INVALID_CONTENT_LENGTH => 'Content-Length header is required.',
61 self::INVALID_CONTENT_NAME => 'X-Upload-Content-Name header is required.',
62 self::INVALID_FILENAME => 'Filename is invalid.',
63 self::INVALID_RANGE_SIZE => 'Range chunk file size (#rangeChunkSize#) is not equal Content-Length (#contentLength#).',
64 self::INVALID_CHUNK_SIZE => 'Chunk file size (#chunkSize#) is not equal Content-Length (#contentLength#).',
65 self::INVALID_CHUNK_OFFSET => 'Chunk offset is invalid.',
66 self::TOO_BIG_REQUEST => 'The content length is too big to process the request.',
67 self::FILE_FIND_FAILED => 'Could not find a file.',
68 self::FILE_MOVE_FAILED => 'Could not move file.',
69 self::FILE_APPEND_NOT_FOUND => 'File not found.',
70 self::CHUNK_NOT_FOUND => 'Could not find chunk file.',
71 self::CHUNK_COPY_FAILED => 'Could not copy chunk file.',
72 self::CHUNK_TOO_BIG => 'You cannot upload a chunk more than the file size.',
73 self::CHUNK_APPEND_NOT_FOUND => 'Could not find chunk.',
74 self::CHUNK_APPEND_FAILED => 'Could not put contents to file.',
75 self::CLOUD_EMPTY_BUCKET => 'Could not get the cloud bucket.',
76 self::CLOUD_INVALID_CHUNK_SIZE => 'Cannot upload file to cloud. The size of the chunk (#chunkSize#) must be more than #minUploadSize#. Check "post_max_size" (#postMaxSize#) and "upload_max_filesize" (#uploadMaxFileSize#) options in php.ini.',
77 self::CLOUD_GET_CONTENTS_FAILED => 'Could not get file contents.',
78 self::CLOUD_START_UPLOAD_FAILED => 'Could not start cloud upload.',
79 self::CLOUD_FINISH_UPLOAD_FAILED => 'Could not finish cloud upload.',
80 self::CLOUD_UPLOAD_FAILED => 'Could not upload file for #fails# times.',
81 self::EMPTY_TOKEN => 'Could not append content to file. Have to set token parameter.',
82 self::UNKNOWN_TOKEN => 'Could not find file by token.',
83 self::INVALID_SIGNATURE => 'Token signature is invalid.',
84 ];
85
86 public function __construct(string $code, ...$args)
87 {
88 $message = isset($args[0]) && is_string($args[0]) ? $args[0] : null;
89 $description = isset($args[1]) && is_string($args[1]) ? $args[1] : null;
90 $lastIndex = count($args) - 1;
91 $customData = isset($args[$lastIndex]) && is_array($args[$lastIndex]) ? $args[$lastIndex] : [];
92
93 $replacements = [];
94 foreach ($customData as $key => $value)
95 {
96 $replacements["#{$key}#"] = $value;
97 }
98
99 if (isset(self::$systemErrors[$code]))
100 {
101 $message = self::$systemErrors[$code];
102 foreach ($replacements as $search => $repl)
103 {
104 $message = str_replace($search, $repl, $message);
105 }
106
107 $this->setSystem(true);
108 $description = '';
109 }
110
111 if (!is_string($message))
112 {
113 $message = Loc::getMessage("UPLOADER_{$code}", $replacements);
114 }
115
116 if (is_string($message) && mb_strlen($message) > 0 && !is_string($description))
117 {
118 $description = Loc::getMessage("UPLOADER_{$code}_DESC", $replacements);
119 }
120
121 if (!is_string($message) || mb_strlen($message) === 0)
122 {
123 $message = $code;
124 }
125
126 parent::__construct($message, $code, $customData);
127
128 if (is_string($description))
129 {
130 $this->setDescription($description);
131 }
132 }
133
134 public function getDescription(): string
135 {
136 return $this->description;
137 }
138
139 public function setDescription(string $description): void
140 {
141 $this->description = $description;
142 }
143
144 public function isSystem(): bool
145 {
146 return $this->system;
147 }
148
149 public function setSystem(bool $system): void
150 {
151 $this->system = $system;
152 }
153
154 public function jsonSerialize()
155 {
156 return [
157 'message' => $this->getMessage(),
158 'code' => $this->getCode(),
159 'type' => 'file-uploader',
160 'system' => $this->isSystem(),
161 'description' => $this->getDescription(),
162 'customData' => $this->getCustomData(),
163 ];
164 }
165}
static loadLanguageFile($file, $language=null, $normalize=true)
Definition loc.php:224
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
__construct(string $code,... $args)