Integration
1 year ago
Vendors
2 months ago
.htaccess
1 year ago
Destination.php
2 months ago
DestinationDiskUsage.php
1 year ago
DestinationFile.php
1 year ago
DestinationWrapper.php
1 year ago
ScanDirIterator.php
1 year ago
ScanDirIteratorFile.php
9 months ago
Tree.php
1 year ago
index.html
1 year ago
web.config
1 year ago
DestinationWrapper.php
94 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Destination; |
| 4 | |
| 5 | use JetBackup\Data\ArrayData; |
| 6 | use JetBackup\Exception\DBException; |
| 7 | use JetBackup\Log\LogController; |
| 8 | use SleekDB\Exceptions\InvalidArgumentException; |
| 9 | use SleekDB\Exceptions\IOException; |
| 10 | |
| 11 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 12 | |
| 13 | abstract class DestinationWrapper implements \JetBackup\Destination\Integration\Destination { |
| 14 | |
| 15 | private ?string $_destination_name; |
| 16 | private int $_destination_id; |
| 17 | private LogController $_log_controller; |
| 18 | private ArrayData $_options; |
| 19 | private int $_chunk_size; |
| 20 | private string $_path; |
| 21 | |
| 22 | public function __construct(int $chunk_size, string $path, ?LogController $logController=null, ?string $name=null, int $id=0) { |
| 23 | $this->_destination_name = $name; |
| 24 | $this->_destination_id = $id; |
| 25 | $this->_log_controller = $logController ?: new LogController(); |
| 26 | $this->_options = new ArrayData(); |
| 27 | $this->_chunk_size = $chunk_size; |
| 28 | $this->_path = $path; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @return string |
| 33 | */ |
| 34 | public function getName():string { return $this->_destination_name; } |
| 35 | |
| 36 | /** |
| 37 | * @return int |
| 38 | */ |
| 39 | public function getId():int { return $this->_destination_id; } |
| 40 | |
| 41 | /** |
| 42 | * @return string |
| 43 | */ |
| 44 | public function getPath():string { return preg_replace("#/+#", '/', $this->_path); } |
| 45 | |
| 46 | /** |
| 47 | * @param string $path |
| 48 | * |
| 49 | * @return string |
| 50 | */ |
| 51 | public function getRealPath(string $path): string { return preg_replace("#/+#", '/', $this->getPath() . '/' . $path); } |
| 52 | |
| 53 | /** |
| 54 | * @param string $path |
| 55 | * |
| 56 | * @return string |
| 57 | */ |
| 58 | public function removeRealPath(string $path):string { return preg_replace("#^" . preg_quote($this->getPath()) . "#", "", $path); } |
| 59 | |
| 60 | /** |
| 61 | * @return LogController |
| 62 | */ |
| 63 | public function getLogController():LogController { return $this->_log_controller; } |
| 64 | |
| 65 | /** |
| 66 | * @return int |
| 67 | */ |
| 68 | public function getChunkSize():int { return $this->_chunk_size; } |
| 69 | |
| 70 | /** |
| 71 | * @return ArrayData |
| 72 | */ |
| 73 | public function getOptions():ArrayData { return $this->_options; } |
| 74 | |
| 75 | public function setSerializedData( string $data ) { |
| 76 | $this->setData((object) json_decode($data)); |
| 77 | } |
| 78 | |
| 79 | public function getSerializedData(): string { |
| 80 | return json_encode($this->getData()); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @throws InvalidArgumentException |
| 85 | * @throws IOException |
| 86 | * @throws DBException |
| 87 | */ |
| 88 | public function save():void { |
| 89 | if(!$this->getId()) return; |
| 90 | $destination = new Destination($this->getId()); |
| 91 | if(!$destination->getId()) return; |
| 92 | $destination->updateSerializedData($this->getSerializedData()); |
| 93 | } |
| 94 | } |