mirror of
https://github.com/zoe-may/TDoG-Skin.git
synced 2024-11-24 05:42:19 +08:00
36 lines
770 B
PHP
Executable File
36 lines
770 B
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services;
|
|
|
|
use Exception;
|
|
use Illuminate\Filesystem\Filesystem;
|
|
use ZipArchive;
|
|
|
|
class Unzip
|
|
{
|
|
protected Filesystem $filesystem;
|
|
|
|
protected ZipArchive $zipper;
|
|
|
|
public function __construct(Filesystem $filesystem, ZipArchive $zipper)
|
|
{
|
|
$this->filesystem = $filesystem;
|
|
$this->zipper = $zipper;
|
|
}
|
|
|
|
public function extract(string $file, string $destination): void
|
|
{
|
|
$zip = $this->zipper;
|
|
$resource = $zip->open($file);
|
|
|
|
if ($resource === true && $zip->extractTo($destination)) {
|
|
$zip->close();
|
|
$this->filesystem->delete($file);
|
|
} else {
|
|
throw new Exception(trans('admin.download.errors.unzip'));
|
|
}
|
|
}
|
|
}
|