Skip to content

Commit 0e0c095

Browse files
committed
refactor to Config class
1 parent b8b5e50 commit 0e0c095

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
],
2020
"require": {
21-
"php": "^8.1",
21+
"php": "^8.2",
2222
"ext-zip": "^1.14.0",
2323
"illuminate/console": "^10.10.0|^11.0",
2424
"illuminate/contracts": "^10.10.0|^11.0",

src/BackupDestination/BackupDestination.php

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Exception;
77
use Illuminate\Contracts\Filesystem\Factory;
88
use Illuminate\Contracts\Filesystem\Filesystem;
9+
use Spatie\Backup\Config\Config;
910
use Spatie\Backup\Exceptions\InvalidBackupDestination;
1011

1112
class BackupDestination

src/Tasks/Backup/Zip.php

+18-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Spatie\Backup\Tasks\Backup;
44

55
use Illuminate\Support\Str;
6+
use Spatie\Backup\Config\Config;
67
use Spatie\Backup\Helpers\Format;
78
use ZipArchive;
89

@@ -12,10 +13,23 @@ class Zip
1213

1314
protected int $fileCount = 0;
1415

16+
protected Config $config;
17+
18+
public function __construct(protected string $pathToZip)
19+
{
20+
$this->zipFile = new ZipArchive();
21+
$this->config = app(Config::class);
22+
23+
$this->open();
24+
}
25+
1526
public static function createForManifest(Manifest $manifest, string $pathToZip): self
1627
{
17-
$relativePath = config('backup.backup.source.files.relative_path') ?
18-
rtrim((string) config('backup.backup.source.files.relative_path'), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR : false;
28+
$config = app(Config::class);
29+
30+
$relativePath = $config->backup->source->files->relativePath
31+
? rtrim($config->backup->source->files->relativePath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR
32+
: false;
1933

2034
$zip = new static($pathToZip);
2135

@@ -47,13 +61,6 @@ protected static function determineNameOfFileInZip(string $pathToFile, string $p
4761
return $pathToFile;
4862
}
4963

50-
public function __construct(protected string $pathToZip)
51-
{
52-
$this->zipFile = new ZipArchive();
53-
54-
$this->open();
55-
}
56-
5764
public function path(): string
5865
{
5966
return $this->pathToZip;
@@ -93,8 +100,8 @@ public function add(string|iterable $files, ?string $nameInZip = null): self
93100
$files = [$files];
94101
}
95102

96-
$compressionMethod = config('backup.backup.destination.compression_method', null);
97-
$compressionLevel = config('backup.backup.destination.compression_level', 9);
103+
$compressionMethod = $this->config->backup->destination->compressionMethod;
104+
$compressionLevel = $this->config->backup->destination->compressionLevel;
98105

99106
foreach ($files as $file) {
100107
if (is_dir($file)) {

src/Traits/Retryable.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,19 @@ protected function setTries(string $type): void
3737
return;
3838
}
3939

40-
$this->tries = (int) config('backup.'.$type.'.tries', 1);
40+
$this->tries = match ($type) {
41+
'backup' => $this->config->backup->tries,
42+
'cleanup' => $this->config->cleanup->tries,
43+
default => 1,
44+
};
4145
}
4246

4347
protected function getRetryDelay(string $type): int
4448
{
45-
return (int) config('backup.'.$type.'.retry_delay', 0);
49+
return match ($type) {
50+
'backup' => $this->config->backup->retryDelay,
51+
'cleanup' => $this->config->cleanup->retryDelay,
52+
default => 0,
53+
};
4654
}
4755
}

0 commit comments

Comments
 (0)