1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Spiral Framework. |
5
|
|
|
* |
6
|
|
|
* @license MIT |
7
|
|
|
* @author Anton Titov (Wolfy-J) |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Spiral\Bootloader; |
13
|
|
|
|
14
|
|
|
use Psr\Log\LoggerInterface; |
15
|
|
|
use Spiral\Boot\Bootloader\Bootloader; |
16
|
|
|
use Spiral\Boot\DirectoriesInterface; |
17
|
|
|
use Spiral\Boot\EnvironmentInterface; |
18
|
|
|
use Spiral\Exceptions\HandlerInterface; |
19
|
|
|
use Spiral\Exceptions\PlainHandler; |
20
|
|
|
use Spiral\Files\FilesInterface; |
21
|
|
|
use Spiral\Snapshots\FileSnapshooter; |
22
|
|
|
use Spiral\Snapshots\SnapshotterInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Depends on environment variables: |
26
|
|
|
* SNAPSHOT_MAX_FILES: defaults to 25 |
27
|
|
|
* SNAPSHOT_VERBOSITY: defaults to HandlerInterface::VERBOSITY_VERBOSE (1) |
28
|
|
|
*/ |
29
|
|
|
final class SnapshotsBootloader extends Bootloader |
30
|
|
|
{ |
31
|
|
|
protected const SINGLETONS = [ |
32
|
|
|
SnapshotterInterface::class => [self::class, 'fileSnapshooter'] |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
private const MAX_SNAPSHOTS = 25; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param EnvironmentInterface $env |
39
|
|
|
* @param DirectoriesInterface $dirs |
40
|
|
|
* @param FilesInterface $files |
41
|
|
|
* @param LoggerInterface|null $logger |
42
|
|
|
* @return FileSnapshooter |
43
|
|
|
*/ |
44
|
|
|
private function fileSnapshooter( |
45
|
|
|
EnvironmentInterface $env, |
46
|
|
|
DirectoriesInterface $dirs, |
47
|
|
|
FilesInterface $files, |
48
|
|
|
LoggerInterface $logger = null |
49
|
|
|
) { |
50
|
|
|
return new FileSnapshooter( |
51
|
|
|
$dirs->get('runtime') . '/snapshots/', |
52
|
|
|
$env->get('SNAPSHOT_MAX_FILES', self::MAX_SNAPSHOTS), |
53
|
|
|
$env->get('SNAPSHOT_VERBOSITY', HandlerInterface::VERBOSITY_VERBOSE), |
54
|
|
|
new PlainHandler(), |
55
|
|
|
$files, |
56
|
|
|
$logger |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|