Bootstrap   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
c 1
b 0
f 1
dl 0
loc 64
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 3 1
A loading() 0 13 3
A app() 0 3 1
A __construct() 0 3 1
A kernel() 0 3 1
1
<?php
2
/**
3
 * Console bootstrap
4
 * User: moyo
5
 * Date: 12/12/2017
6
 * Time: 6:06 PM
7
 */
8
9
namespace Carno\Console;
10
11
use Carno\Console\Chips\LDKit;
12
use Carno\Console\Contracts\Bootable;
13
use Carno\Container\DI;
14
15
class Bootstrap
16
{
17
    use LDKit;
18
19
    /**
20
     * @var App
21
     */
22
    private $app = null;
23
24
    /**
25
     * @var string[]
26
     */
27
    private $kms = [];
28
29
    /**
30
     * Bootstrap constructor.
31
     * @param App $app
32
     */
33
    public function __construct(App $app)
34
    {
35
        $this->app = $app;
36
    }
37
38
    /**
39
     * @return App
40
     */
41
    public function app() : App
42
    {
43
        return $this->app;
44
    }
45
46
    /**
47
     * setting kernel mods
48
     * @param string ...$mods
49
     */
50
    public function register(string ...$mods) : void
51
    {
52
        $this->kms = array_unique(array_merge($this->kms, $mods));
53
    }
54
55
    /**
56
     * booting kernel mods
57
     */
58
    public function kernel() : void
59
    {
60
        $this->loading(...$this->kms);
61
    }
62
63
    /**
64
     * @param string ...$mods
65
     */
66
    public function loading(string ...$mods) : void
67
    {
68
        /**
69
         * @var Bootable[] $boots
70
         */
71
72
        $boots = [];
73
74
        foreach ($mods as $mod) {
75
            ($com = DI::object($mod)) instanceof Bootable && $boots[] = $com;
76
        }
77
78
        $this->booting($this->app, ...$boots);
79
    }
80
}
81