Passed
Push — master ( 8926af...beb5fc )
by Anton
02:16
created

MigrationsBootloader::defineDependencies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
declare(strict_types=1);
9
10
namespace Spiral\Bootloader\Database;
11
12
use Spiral\Boot\Bootloader\Bootloader;
13
use Spiral\Boot\DirectoriesInterface;
14
use Spiral\Boot\EnvironmentInterface;
15
use Spiral\Bootloader\TokenizerBootloader;
16
use Spiral\Config\ConfiguratorInterface;
17
use Spiral\Migrations\FileRepository;
18
use Spiral\Migrations\Migrator;
19
use Spiral\Migrations\RepositoryInterface;
20
21
final class MigrationsBootloader extends Bootloader
22
{
23
    const DEPENDENCIES = [
24
        TokenizerBootloader::class,
25
        DatabaseBootloader::class
26
    ];
27
28
    const SINGLETONS = [
29
        Migrator::class            => Migrator::class,
30
        RepositoryInterface::class => FileRepository::class
31
    ];
32
33
    /**
34
     * @param ConfiguratorInterface $config
35
     * @param EnvironmentInterface  $env
36
     * @param DirectoriesInterface  $dirs
37
     */
38
    public function boot(
39
        ConfiguratorInterface $config,
40
        EnvironmentInterface $env,
41
        DirectoriesInterface $dirs
42
    ) {
43
        if (!$dirs->has('migrations')) {
44
            $dirs->set('migrations', $dirs->get('app') . 'migrations');
45
        }
46
47
        $config->setDefaults('migration', [
48
            'directory' => $dirs->get('migrations'),
49
            'table'     => 'migrations',
50
            'safe'      => $env->get('SAFE_MIGRATIONS', false)
51
        ]);
52
    }
53
}
54