1 <?php declare(strict_types=1);
3 namespace Cli\Services;
9 protected ZipArchive $zip;
10 public function __construct(
11 protected string $filePath
13 $this->zip = new ZipArchive();
14 $status = $this->zip->open($this->filePath);
16 if (!file_exists($this->filePath) || $status !== true) {
17 throw new \Exception("Could not open file [{$this->filePath}] as ZIP");
22 * @return array<string, array{desc: string, exists: bool}>
24 public function getContentsOverview(): array
28 'desc' => '.env Config File',
29 'exists' => boolval($this->zip->statName('.env')),
32 'desc' => 'Themes Folder',
33 'exists' => $this->hasFolder('themes/'),
36 'desc' => 'Public File Uploads',
37 'exists' => $this->hasFolder('public/uploads/'),
39 'storage/uploads' => [
40 'desc' => 'Private File Uploads',
41 'exists' => $this->hasFolder('storage/uploads/'),
44 'desc' => 'Database Dump',
45 'exists' => boolval($this->zip->statName('db.sql')),
50 public function extractInto(string $directoryPath): void
52 $result = $this->zip->extractTo($directoryPath);
54 throw new \Exception("Failed extraction of ZIP into [{$directoryPath}].");
58 protected function hasFolder($folderPath): bool
60 for ($i = 0; $i < $this->zip->numFiles; $i++) {
61 $filePath = $this->zip->getNameIndex($i);
62 if (str_starts_with($filePath, $folderPath)) {