Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
UploadResult.php
1<?php
2
4
6
7class UploadResult extends \Bitrix\Main\Result implements \JsonSerializable
8{
9 protected ?TempFile $tempFile = null;
10 protected ?FileInfo $file = null;
11 protected ?string $token = null;
12 protected bool $done = false;
13
14 public static function reject(Error $error): self
15 {
16 $result = new static();
17 $result->addError($error);
18
19 return $result;
20 }
21
26 public function addError(Error $error)
27 {
28 if ($error instanceof UploaderError)
29 {
30 return parent::addError($error);
31 }
32 else
33 {
34 return parent::addError(new UploaderError(
35 $error->getCode(),
36 $error->getMessage(),
37 $error->getCustomData()
38 ));
39 }
40 }
41
42 public function addErrors(array $errors)
43 {
44 foreach ($errors as $error)
45 {
46 $this->addError($error);
47 }
48
49 return $this;
50 }
51
52 public function getTempFile(): ?TempFile
53 {
54 return $this->tempFile;
55 }
56
57 public function setTempFile(TempFile $tempFile): void
58 {
59 $this->tempFile = $tempFile;
60 }
61
62 public function getFileInfo(): ?FileInfo
63 {
64 return $this->file;
65 }
66
67 public function setFileInfo(?FileInfo $file): void
68 {
69 $this->file = $file;
70 }
71
72 public function getToken(): ?string
73 {
74 return $this->token;
75 }
76
77 public function setToken(string $token)
78 {
79 $this->token = $token;
80 }
81
82 public function setDone(bool $done): void
83 {
84 $this->done = $done;
85 }
86
87 public function isDone(): bool
88 {
89 return $this->done;
90 }
91
92 public function jsonSerialize(): array
93 {
94 return [
95 'token' => $this->getToken(),
96 'done' => $this->isDone(),
97 'file' => $this->getFileInfo(),
98 ];
99 }
100}