| Total Complexity | 3 |
| Total Lines | 57 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class Password |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Path to .zip-file |
||
| 14 | * |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | public $path; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * The chosen password |
||
| 21 | * |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $password; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Read the .zip, apply password and encryption, then rewrite the file |
||
| 28 | * |
||
| 29 | * @param string $path |
||
| 30 | */ |
||
| 31 | function __construct(string $path) |
||
| 32 | { |
||
| 33 | $this->password = config('backup-shield.password'); |
||
| 34 | |||
| 35 | // If no password is set, just return the backup-path |
||
| 36 | if (!$this->password) { |
||
| 37 | return $this->path = $path; |
||
| 38 | } |
||
| 39 | |||
| 40 | consoleOutput()->info('Applying password and encryption to zip using ZipArchive...'); |
||
| 41 | |||
| 42 | $this->makeZip($path); |
||
| 43 | |||
| 44 | consoleOutput()->info('Successfully applied password and encryption to zip.'); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Use native PHP ZipArchive |
||
| 49 | * |
||
| 50 | * @return void |
||
| 51 | */ |
||
| 52 | protected function makeZip(string $path): void |
||
| 67 | } |
||
| 68 | } |
||
| 69 |