PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.8.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.8.2
4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Backup / Dto / Service / ArchiverDto.php
wp-staging / Backup / Dto / Service Last commit date
ArchiverDto.php 2 years ago
ArchiverDto.php
204 lines
1 <?php
2
3 namespace WPStaging\Backup\Dto\Service;
4
5 use WPStaging\Backup\Entity\BackupMetadata;
6
7 class ArchiverDto
8 {
9 /** @var string */
10 private $filePath;
11
12 /** @var string */
13 private $indexPath;
14
15 /** @var int */
16 private $fileHeaderBytes = 0;
17
18 /** @var int */
19 private $writtenBytesTotal = 0;
20
21 /** @var int */
22 private $fileSize;
23
24 /** @var array */
25 private $indexPositionCreated = [];
26
27 /** @var BackupMetadata */
28 private $backupMetadata;
29
30 /**
31 * @param int $bytes
32 * @return void
33 */
34 public function appendWrittenBytes(int $bytes)
35 {
36 $this->writtenBytesTotal += (int) $bytes;
37 }
38
39 /**
40 * @return bool
41 */
42 public function isFinished(): bool
43 {
44 return $this->fileSize <= $this->writtenBytesTotal;
45 }
46
47 /**
48 * @return void
49 */
50 public function resetIfFinished()
51 {
52 if ($this->isFinished()) {
53 $this->reset();
54 }
55 }
56
57 /**
58 * @return void
59 */
60 public function reset()
61 {
62 $this->setFileSize(-1);
63 $this->setFilePath('');
64 $this->setWrittenBytesTotal(0);
65 $this->setIndexPositionCreated(false);
66 }
67
68 /**
69 * @return string
70 */
71 public function getFilePath(): string
72 {
73 return (string)$this->filePath;
74 }
75
76 /**
77 * @param string $filePath
78 * @return void
79 */
80 public function setFilePath(string $filePath)
81 {
82 $this->filePath = wp_normalize_path((string)$filePath);
83 }
84
85 /**
86 * @return string
87 */
88 public function getIndexPath(): string
89 {
90 return $this->indexPath;
91 }
92
93 /**
94 * @param string $indexPath
95 * @return void
96 */
97 public function setIndexPath(string $indexPath)
98 {
99 $this->indexPath = wp_normalize_path((string)$indexPath);
100 }
101
102 /**
103 * @return int
104 */
105 public function getWrittenBytesTotal(): int
106 {
107 /** @noinspection UnnecessaryCastingInspection */
108 return (int) $this->writtenBytesTotal;
109 }
110
111 /**
112 * @param int $writtenBytesTotal
113 * @return void
114 */
115 public function setWrittenBytesTotal(int $writtenBytesTotal)
116 {
117 $this->writtenBytesTotal = $writtenBytesTotal;
118 }
119
120 /**
121 * @return int
122 */
123 public function getFileSize(): int
124 {
125 return (int)$this->fileSize;
126 }
127
128 /**
129 * @param int $fileSize
130 * @return void
131 */
132 public function setFileSize(int $fileSize)
133 {
134 $this->fileSize = $fileSize;
135 }
136
137 /**
138 * @return int
139 */
140 public function getFileHeaderBytes(): int
141 {
142 return $this->fileHeaderBytes;
143 }
144
145 /**
146 * @param int $fileHeaderBytes
147 * @return void
148 */
149 public function setFileHeaderBytes(int $fileHeaderBytes)
150 {
151 $this->fileHeaderBytes = $fileHeaderBytes;
152 }
153
154 /**
155 * @param string $category
156 * @param int $categoryIndex
157 * @return bool
158 */
159 public function isIndexPositionCreated(string $category = '', int $categoryIndex = 0): bool
160 {
161 if (!isset($this->indexPositionCreated[$category])) {
162 return false;
163 }
164
165 return (bool)$this->indexPositionCreated[$category][$categoryIndex];
166 }
167
168 /**
169 * @param bool $indexPositionCreated
170 * @param string $category
171 * @param int $categoryIndex
172 * @return void
173 */
174 public function setIndexPositionCreated(bool $indexPositionCreated, string $category = '', int $categoryIndex = 0)
175 {
176 if (!isset($this->indexPositionCreated[$category])) {
177 $this->indexPositionCreated[$category] = [];
178 }
179
180 $this->indexPositionCreated[$category][$categoryIndex] = (bool)$indexPositionCreated;
181 }
182
183 /**
184 * @return BackupMetadata
185 */
186 public function getBackupMetadata(): BackupMetadata
187 {
188 if (!$this->backupMetadata) {
189 $this->backupMetadata = new BackupMetadata();
190 }
191
192 return $this->backupMetadata;
193 }
194
195 /**
196 * @param BackupMetadata $backupMetadata
197 * @return void
198 */
199 public function setBackupMetadata(BackupMetadata $backupMetadata)
200 {
201 $this->backupMetadata = $backupMetadata;
202 }
203 }
204