Passed
Push — master ( 2ab9ec...990ee9 )
by Attila
49:42
created

  A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Contains the BaseBoxServiceProvider class.
7
 *
8
 * @copyright   Copyright (c) 2016 Attila Fulop
9
 * @author      Attila Fulop
10
 * @license     MIT
11
 * @since       2016-12-29
12
 *
13
 */
14
15
namespace Konekt\Concord;
16
17
use Konekt\Concord\Concerns\LoadsSubmodules;
18
19
abstract class BaseBoxServiceProvider extends BaseServiceProvider
20
{
21
    use LoadsSubmodules;
22
23
    protected $configFileName = 'box.php';
24
25
    protected static $_kind = 'box';
26
27
    public function register()
28
    {
29
        parent::register();
30
31
        $modules = $this->config("modules", []);
32
33
        if (is_array($modules)) {
34
            $this->loadSubModules($modules);
35
        }
36
    }
37
38
    public function boot()
39
    {
40
        parent::boot();
41
42
        $this->publishOwnMigrationsInASeparateGroup();
43
        $this->publishAllSubModuleMigrations();
44
    }
45
46
    private function publishAllSubModuleMigrations(): void
47
    {
48
        $folder = '/' . $this->convention->migrationsFolder();
49
        $moduleMigrationPaths = [
50
            $this->getBasePath() . $folder => database_path('migrations')
51
        ];
52
        foreach ($this->config("modules", []) as $moduleClass => $config) {
53
            $module = $this->concord->module($this->getModuleId($moduleClass));
54
            $moduleMigrationPaths[$module->getBasePath() . $folder] = database_path('migrations');
55
        }
56
57
        $this->publishes($moduleMigrationPaths, 'migrations');
58
    }
59
60
    private function publishOwnMigrationsInASeparateGroup()
61
    {
62
        $this->publishes([
63
            $this->getBasePath() . '/' . $this->convention->migrationsFolder() =>
64
                database_path('migrations')
65
        ], 'own-migrations-only');
66
    }
67
}
68