1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Spiral\Bootloader; |
6
|
|
|
|
7
|
|
|
use Spiral\Boot\Bootloader\Bootloader; |
8
|
|
|
use Spiral\Boot\EnvironmentInterface; |
9
|
|
|
use Spiral\Core\FactoryInterface; |
10
|
|
|
use Spiral\Snapshots\SnapshotterInterface; |
11
|
|
|
use Spiral\Snapshots\StorageSnapshooter; |
12
|
|
|
use Spiral\Snapshots\StorageSnapshot; |
13
|
|
|
use Spiral\Storage\Bootloader\StorageBootloader; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Depends on environment variables: |
17
|
|
|
* SNAPSHOTS_BUCKET: bucket name |
18
|
|
|
* SNAPSHOTS_DIRECTORY: where snapshots will be stored in the bucket |
19
|
|
|
* SNAPSHOT_VERBOSITY: defaults to {@see \Spiral\Exceptions\Verbosity::VERBOSE} (1) |
20
|
|
|
*/ |
21
|
|
|
final class StorageSnapshotsBootloader extends Bootloader |
22
|
|
|
{ |
23
|
|
|
protected const DEPENDENCIES = [ |
24
|
|
|
StorageBootloader::class, |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
protected const SINGLETONS = [ |
28
|
|
|
StorageSnapshot::class => [self::class, 'storageSnapshot'], |
29
|
|
|
SnapshotterInterface::class => StorageSnapshooter::class, |
30
|
|
|
]; |
31
|
|
|
|
32
|
2 |
|
private function storageSnapshot(EnvironmentInterface $env, FactoryInterface $factory): StorageSnapshot |
33
|
|
|
{ |
34
|
2 |
|
$bucket = $env->get('SNAPSHOTS_BUCKET'); |
35
|
|
|
|
36
|
2 |
|
if ($bucket === null) { |
37
|
|
|
throw new \RuntimeException( |
38
|
|
|
'Please, configure a bucket for storing snapshots using the environment variable `SNAPSHOTS_BUCKET`.' |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
2 |
|
return $factory->make(StorageSnapshot::class, [ |
43
|
2 |
|
'bucket' => $bucket, |
44
|
2 |
|
'directory' => $env->get('SNAPSHOTS_DIRECTORY', null), |
45
|
2 |
|
]); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|