| 1 |
<?php |
| 2 |
|
| 3 |
namespace JetBackup\Destination; |
| 4 |
|
| 5 |
use JetBackup\Data\ArrayData; |
| 6 |
use JetBackup\Destination\Integration\DestinationFile as iDestinationFile; |
| 7 |
use JetBackup\Entities\Util; |
| 8 |
|
| 9 |
defined( '__JETBACKUP__' ) or die( 'Restricted access' ); |
| 10 |
|
| 11 |
class DestinationFile extends ArrayData implements iDestinationFile { |
| 12 |
|
| 13 |
const FILE_ID = 'file_id'; |
| 14 |
const FILES_DIR = 'files_dir'; |
| 15 |
const PATH = 'path'; |
| 16 |
const NAME = 'name'; |
| 17 |
const TYPE = 'type'; |
| 18 |
const SIZE = 'size'; |
| 19 |
const MTIME = 'mtime'; |
| 20 |
const OWNER = 'owner'; |
| 21 |
const GROUP = 'group'; |
| 22 |
const FILE_DATA = 'file_data'; |
| 23 |
const PERMISSIONS = 'permissions'; |
| 24 |
const LINK_TARGET = 'link_target'; |
| 25 |
|
| 26 |
/** |
| 27 |
* @return string |
| 28 |
*/ |
| 29 |
public function getPath(): string { return $this->get(self::PATH); } |
| 30 |
|
| 31 |
/** |
| 32 |
* @param string $path |
| 33 |
* |
| 34 |
* @return void |
| 35 |
*/ |
| 36 |
public function setPath(string $path):void { $this->set(self::PATH, $path); } |
| 37 |
|
| 38 |
/** |
| 39 |
* @return string |
| 40 |
*/ |
| 41 |
public function getName(): string { return $this->get(self::NAME); } |
| 42 |
|
| 43 |
/** |
| 44 |
* @param string $name |
| 45 |
* |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
public function setName(string $name):void { $this->set(self::NAME, $name); } |
| 49 |
|
| 50 |
/** |
| 51 |
* @return string |
| 52 |
*/ |
| 53 |
public function getFullPath(): string { return preg_replace("/^\/+/", "", $this->getPath() . '/' . $this->getName()); } |
| 54 |
|
| 55 |
/** |
| 56 |
* @return int |
| 57 |
*/ |
| 58 |
public function getType(): int { return (int) $this->get(self::TYPE, 0); } |
| 59 |
|
| 60 |
/** |
| 61 |
* @param int $type |
| 62 |
* |
| 63 |
* @return void |
| 64 |
*/ |
| 65 |
public function setType(int $type):void { $this->set(self::TYPE, $type); } |
| 66 |
|
| 67 |
/** |
| 68 |
* @return int |
| 69 |
*/ |
| 70 |
public function getSize(): int { return (int) $this->get(self::SIZE, 0); } |
| 71 |
|
| 72 |
/** |
| 73 |
* @param int $size |
| 74 |
* |
| 75 |
* @return void |
| 76 |
*/ |
| 77 |
public function setSize(int $size):void { $this->set(self::SIZE, $size); } |
| 78 |
|
| 79 |
/** |
| 80 |
* @return int |
| 81 |
*/ |
| 82 |
public function getModifyTime(): int { return (int) $this->get(self::MTIME, 0); } |
| 83 |
|
| 84 |
/** |
| 85 |
* @param int $time |
| 86 |
* |
| 87 |
* @return void |
| 88 |
*/ |
| 89 |
public function setModifyTime(int $time):void { $this->set(self::MTIME, $time); } |
| 90 |
|
| 91 |
/** |
| 92 |
* @return string |
| 93 |
*/ |
| 94 |
public function getOwner(): string { return $this->get(self::OWNER, 'root'); } |
| 95 |
|
| 96 |
/** |
| 97 |
* @param string $owner |
| 98 |
* |
| 99 |
* @return void |
| 100 |
*/ |
| 101 |
public function setOwner(string $owner):void { $this->set(self::OWNER, $owner); } |
| 102 |
|
| 103 |
/** |
| 104 |
* @return string |
| 105 |
*/ |
| 106 |
public function getGroup(): string { return $this->get(self::GROUP, 'root'); } |
| 107 |
|
| 108 |
/** |
| 109 |
* @param string $group |
| 110 |
* |
| 111 |
* @return void |
| 112 |
*/ |
| 113 |
public function setGroup(string $group):void { $this->set(self::GROUP, $group); } |
| 114 |
|
| 115 |
/** |
| 116 |
* @return int |
| 117 |
*/ |
| 118 |
public function getPermissions():int { return $this->get(self::PERMISSIONS, 0000); } |
| 119 |
|
| 120 |
/** |
| 121 |
* @param int $permissions |
| 122 |
* |
| 123 |
* @return void |
| 124 |
*/ |
| 125 |
public function setPermissions(int $permissions):void { $this->set(self::PERMISSIONS, $permissions); } |
| 126 |
|
| 127 |
/** |
| 128 |
* @return string |
| 129 |
*/ |
| 130 |
public function getLinkTarget():string { return $this->get(self::LINK_TARGET); } |
| 131 |
|
| 132 |
/** |
| 133 |
* @param string $target |
| 134 |
* |
| 135 |
* @return void |
| 136 |
*/ |
| 137 |
public function setLinkTarget(string $target):void { $this->set(self::LINK_TARGET, $target); } |
| 138 |
|
| 139 |
/** |
| 140 |
* @return string |
| 141 |
*/ |
| 142 |
public function getFileId():string { return $this->get(self::FILE_ID); } |
| 143 |
|
| 144 |
/** |
| 145 |
* @param string $id |
| 146 |
* |
| 147 |
* @return void |
| 148 |
*/ |
| 149 |
public function setFileId(string $id):void { $this->set(self::FILE_ID, $id); } |
| 150 |
|
| 151 |
/** |
| 152 |
* @return string |
| 153 |
*/ |
| 154 |
public function getFilesDir():string { return $this->get(self::FILES_DIR); } |
| 155 |
|
| 156 |
/** |
| 157 |
* @param string $dir |
| 158 |
* |
| 159 |
* @return void |
| 160 |
*/ |
| 161 |
public function setFilesDir(string $dir):void { $this->set(self::FILES_DIR, $dir); } |
| 162 |
|
| 163 |
/** |
| 164 |
* @return string |
| 165 |
*/ |
| 166 |
public function getFileData():string { return $this->get(self::FILE_DATA); } |
| 167 |
|
| 168 |
/** |
| 169 |
* @param string $data |
| 170 |
* |
| 171 |
* @return void |
| 172 |
*/ |
| 173 |
public function setFileData(string $data):void { $this->set(self::FILE_DATA, $data); } |
| 174 |
|
| 175 |
/** |
| 176 |
* @param array $file |
| 177 |
* |
| 178 |
* @return DestinationFile |
| 179 |
*/ |
| 180 |
public static function genFile(array $file):DestinationFile { |
| 181 |
|
| 182 |
$item = new DestinationFile(); |
| 183 |
|
| 184 |
if(isset($file['path'])) { |
| 185 |
$item->setPath(Util::mb_dirname($file['path'])); |
| 186 |
$item->setName(Util::mb_basename($file['path'])); |
| 187 |
} |
| 188 |
|
| 189 |
if(isset($file['perms'])) { |
| 190 |
$type = self::TYPE_UNKNOWN; |
| 191 |
$item->setPermissions(/*sprintf("0%o", (0777 & $file['perms']))*/$file['perms']); |
| 192 |
switch($file['perms'] & 0170000) { |
| 193 |
case 0100000: $type = self::TYPE_FILE; break; |
| 194 |
case 0120000: $type = self::TYPE_LINK; break; |
| 195 |
case 0040000: $type = self::TYPE_DIRECTORY; break; |
| 196 |
case 0060000: $type = self::TYPE_BLOCK; break; |
| 197 |
case 0010000: $type = self::TYPE_FIFO; break; |
| 198 |
} |
| 199 |
$item->setType($type); |
| 200 |
} |
| 201 |
|
| 202 |
if(isset($file['size'])) $item->setSize($file['size']); |
| 203 |
if(isset($file['mtime'])) $item->setModifyTime(intval($file['mtime'])); |
| 204 |
if(isset($file['user'])) $item->setOwner($file['user']); |
| 205 |
if(isset($file['group'])) $item->setGroup($file['group']); |
| 206 |
if(isset($file['link'])) $item->setLinkTarget($file['link']); |
| 207 |
if(isset($file['file_id'])) $item->setFileId($file['file_id']); |
| 208 |
if(isset($file['files_dir'])) $item->setFilesDir($file['files_dir']); |
| 209 |
if(isset($file['data'])) $item->setFileData($file['data']); |
| 210 |
|
| 211 |
return $item; |
| 212 |
} |
| 213 |
} |