Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
PendingFile.php
1<?php
2
4
7
9{
10 private string $id;
11 private ?TempFile $tempFile = null;
12 private ErrorCollection $errors;
13 private string $status = PendingFileStatus::INIT;
14
15 public function __construct(string $id)
16 {
17 $this->id = $id;
18 $this->errors = new ErrorCollection();
19 }
20
21 public function getId(): string
22 {
23 return $this->id;
24 }
25
26 public function getGuid(): ?string
27 {
28 return $this->tempFile !== null ? $this->tempFile->getGuid() : null;
29 }
30
31 public function getFileId(): ?int
32 {
33 return $this->isValid() && $this->tempFile !== null ? $this->tempFile->getFileId() : null;
34 }
35
36 public function setTempFile(TempFile $tempFile): void
37 {
38 $this->status = PendingFileStatus::PENDING;
39 $this->tempFile = $tempFile;
40 }
41
42 protected function getTempFile(): ?TempFile
43 {
44 return $this->tempFile;
45 }
46
47 public function getStatus(): string
48 {
49 return $this->status;
50 }
51
52 public function makePersistent(): void
53 {
55 {
56 $this->getTempFile()->makePersistent();
57 $this->status = PendingFileStatus::COMMITTED;
58 }
59 }
60
61 public function remove(): void
62 {
64 {
65 $this->getTempFile()->delete();
66 $this->status = PendingFileStatus::REMOVED;
67 }
68 }
69
70 public function addError(Error $error): void
71 {
72 $this->status = PendingFileStatus::ERROR;
73 $this->errors[] = $error;
74 }
75
76 public function getErrors(): array
77 {
78 return $this->errors->toArray();
79 }
80
81 public function isValid(): bool
82 {
83 return (
86 );
87 }
88}