PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 4.9.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v4.9.2
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 / Staging / Dto / Service / BigFileDto.php
wp-staging / Staging / Dto / Service Last commit date
BigFileDto.php 11 months ago
BigFileDto.php
148 lines
1 <?php
2
3 namespace WPStaging\Staging\Dto\Service;
4
5 class BigFileDto
6 {
7 /** @var string */
8 private $filePath = '';
9
10 /** @var string */
11 private $destinationPath = '';
12
13 /** @var string */
14 private $indexPath = '';
15
16 /** @var int */
17 private $writtenBytesTotal = 0;
18
19 /** @var int */
20 private $fileSize = -1;
21
22 /**
23 * @param int $bytes
24 * @return void
25 */
26 public function appendWrittenBytes(int $bytes)
27 {
28 $this->writtenBytesTotal += (int) $bytes;
29 }
30
31 /**
32 * @return bool
33 */
34 public function isFinished(): bool
35 {
36 return $this->fileSize <= $this->writtenBytesTotal;
37 }
38
39 /**
40 * @return void
41 */
42 public function resetIfFinished()
43 {
44 if ($this->isFinished()) {
45 $this->reset();
46 }
47 }
48
49 /**
50 * @return void
51 */
52 public function reset()
53 {
54 // File can be empty with 0 size, so we need to set it to -1 to indicate that the file size is unknown
55 $this->setFileSize(-1);
56 $this->setFilePath('');
57 $this->setDestinationPath('');
58 $this->setIndexPath('');
59 $this->setWrittenBytesTotal(0);
60 }
61
62 /**
63 * @return string
64 */
65 public function getFilePath(): string
66 {
67 return (string)$this->filePath;
68 }
69
70 /**
71 * @param string $filePath
72 * @return void
73 */
74 public function setFilePath(string $filePath)
75 {
76 $this->filePath = wp_normalize_path($filePath);
77 }
78
79 /**
80 * @return string
81 */
82 public function getDestinationPath(): string
83 {
84 return $this->destinationPath;
85 }
86
87 /**
88 * @param string $destinationPath
89 * @return void
90 */
91 public function setDestinationPath(string $destinationPath)
92 {
93 $this->destinationPath = wp_normalize_path($destinationPath);
94 }
95
96 /**
97 * @return string
98 */
99 public function getIndexPath(): string
100 {
101 return $this->indexPath;
102 }
103
104 /**
105 * @param string $indexPath
106 * @return void
107 */
108 public function setIndexPath(string $indexPath)
109 {
110 $this->indexPath = wp_normalize_path($indexPath);
111 }
112
113 /**
114 * @return int
115 */
116 public function getWrittenBytesTotal(): int
117 {
118 /** @noinspection UnnecessaryCastingInspection */
119 return (int)$this->writtenBytesTotal;
120 }
121
122 /**
123 * @param int $writtenBytesTotal
124 * @return void
125 */
126 public function setWrittenBytesTotal(int $writtenBytesTotal)
127 {
128 $this->writtenBytesTotal = $writtenBytesTotal;
129 }
130
131 /**
132 * @return int
133 */
134 public function getFileSize(): int
135 {
136 return (int)$this->fileSize;
137 }
138
139 /**
140 * @param int $fileSize
141 * @return void
142 */
143 public function setFileSize(int $fileSize)
144 {
145 $this->fileSize = $fileSize;
146 }
147 }
148