Passed
Push — master ( f747df...a125fa )
by Anton
07:27 queued 05:22
created

SnapshotsBootloader::fileSnapshooter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
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