BackupItemDto.php
133 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Backup\Dto\File; |
| 4 | |
| 5 | use WPStaging\Backup\Interfaces\IndexLineInterface; |
| 6 | |
| 7 | /** |
| 8 | * This class is used for representation of item/file in the backup when listing that item/file in the UI. |
| 9 | * |
| 10 | * @package WPStaging\Backup\Dto\File |
| 11 | */ |
| 12 | class BackupItemDto |
| 13 | { |
| 14 | /** |
| 15 | * The offset of the file in the backup |
| 16 | * @var int |
| 17 | */ |
| 18 | private $offset; |
| 19 | |
| 20 | /** |
| 21 | * The line index of the file in the backup |
| 22 | * @var int |
| 23 | */ |
| 24 | private $index; |
| 25 | |
| 26 | /** @var string */ |
| 27 | private $identifiablePath; |
| 28 | |
| 29 | /** @var string */ |
| 30 | private $path; |
| 31 | |
| 32 | /** @var string */ |
| 33 | private $size; |
| 34 | |
| 35 | /** @var bool */ |
| 36 | private $isDatabase; |
| 37 | |
| 38 | public function __construct() |
| 39 | { |
| 40 | $this->offset = 0; |
| 41 | $this->index = 0; |
| 42 | $this->path = ''; |
| 43 | $this->size = ''; |
| 44 | $this->isDatabase = false; |
| 45 | } |
| 46 | |
| 47 | public static function fromIndexLineDto(IndexLineInterface $indexLineDto): BackupItemDto |
| 48 | { |
| 49 | $backupFile = new BackupItemDto(); |
| 50 | $backupFile->setIdentifiablePath($indexLineDto->getIdentifiablePath()); |
| 51 | $backupFile->setSize((string)$indexLineDto->getUncompressedSize()); |
| 52 | $backupFile->setIsDatabase(false); |
| 53 | |
| 54 | return $backupFile; |
| 55 | } |
| 56 | |
| 57 | public function setOffset(int $offset) |
| 58 | { |
| 59 | $this->offset = $offset; |
| 60 | } |
| 61 | |
| 62 | public function setIndex(int $index) |
| 63 | { |
| 64 | $this->index = $index; |
| 65 | } |
| 66 | |
| 67 | public function setIdentifiablePath(string $identifiablePath) |
| 68 | { |
| 69 | $this->identifiablePath = $identifiablePath; |
| 70 | } |
| 71 | |
| 72 | public function setPath(string $path) |
| 73 | { |
| 74 | $this->path = $path; |
| 75 | } |
| 76 | |
| 77 | public function setSize(string $size) |
| 78 | { |
| 79 | $this->size = $size; |
| 80 | } |
| 81 | |
| 82 | public function setIsDatabase(bool $isDatabase) |
| 83 | { |
| 84 | $this->isDatabase = $isDatabase; |
| 85 | } |
| 86 | |
| 87 | public function getOffset(): int |
| 88 | { |
| 89 | return $this->offset; |
| 90 | } |
| 91 | |
| 92 | public function getIndex(): int |
| 93 | { |
| 94 | return $this->index; |
| 95 | } |
| 96 | |
| 97 | public function getIdentifiablePath(): string |
| 98 | { |
| 99 | return $this->identifiablePath; |
| 100 | } |
| 101 | |
| 102 | public function getPath(): string |
| 103 | { |
| 104 | return $this->path; |
| 105 | } |
| 106 | |
| 107 | public function getSize(): string |
| 108 | { |
| 109 | return $this->size; |
| 110 | } |
| 111 | |
| 112 | public function isDatabase(): bool |
| 113 | { |
| 114 | return $this->isDatabase; |
| 115 | } |
| 116 | |
| 117 | public function toArray(): array |
| 118 | { |
| 119 | return [ |
| 120 | 0 => $this->index, |
| 121 | 1 => $this->path, |
| 122 | 2 => $this->offset, |
| 123 | 3 => $this->size, |
| 124 | 4 => $this->isDatabase, |
| 125 | 'offset' => $this->offset, |
| 126 | 'index' => $this->index, |
| 127 | 'path' => $this->path, |
| 128 | 'size' => $this->size, |
| 129 | 'isDatabase' => $this->isDatabase, |
| 130 | ]; |
| 131 | } |
| 132 | } |
| 133 |