Test Failed
Push — master ( 9f82b3...3c8bc2 )
by Alexey
07:31
created

AbstractServiceProvider::kernel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php declare(strict_types = 1);
2
3
namespace Venta\ServiceProvider;
4
5
use Venta\Contracts\Config\ConfigBuilder;
6
use Venta\Contracts\Console\CommandCollection;
7
use Venta\Contracts\Container\Container;
8
use Venta\Contracts\Kernel\Kernel;
9
use Venta\Contracts\ServiceProvider\ServiceProvider;
10
11
/**
12
 * Class AbstractServiceProvider.
13
 *
14
 * @package Venta\ServiceProvider
15
 */
16
abstract class AbstractServiceProvider implements ServiceProvider
17
{
18
    /**
19
     * Service provider name.
20
     *
21
     * @var string
22
     */
23
    protected static $name;
24
25
    /**
26
     * Application config.
27
     *
28
     * @var ConfigBuilder
29
     */
30
    private $configBuilder;
31
32
    /**
33
     * Container instance.
34
     *
35
     * @var Container
36
     */
37
    private $container;
38
39
    /**
40
     * AbstractServiceProvider constructor.
41
     *
42
     * @param Container $container
43
     * @param ConfigBuilder $configBuilder
44
     */
45
    public function __construct(Container $container, ConfigBuilder $configBuilder)
46
    {
47
        $this->container = $container;
48
        $this->configBuilder = $configBuilder;
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public static function dependencies(): array
55
    {
56
        return [];
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62
    final public static function name(): string
63
    {
64
        return static::$name ?: static::class;
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70
    abstract public function boot();
71
72
    /**
73
     * @return Container
74
     */
75
    protected function container(): Container
76
    {
77
        return $this->container;
78
    }
79
80
    /**
81
     * @return Kernel
82
     */
83
    protected function kernel(): Kernel
84
    {
85
        return $this->container()->get(Kernel::class);
86
    }
87
88
    /**
89
     * Merges config params from service provider with the global configuration.
90
     *
91
     * @param string[] ...$configFiles
92
     */
93
    protected function loadConfigFromFiles(string ...$configFiles)
94
    {
95
        foreach ($configFiles as $configFile) {
96
            $this->configBuilder->mergeFile((string)$configFile);
97
        }
98
    }
99
100
    /**
101
     * Registers commands exposed by service provider.
102
     *
103
     * @param string[] ...$commandClasses
104
     */
105
    protected function provideCommands(string ...$commandClasses)
106
    {
107
        /** @var CommandCollection $commandCollector */
108
        $commandCollector = $this->container->get(CommandCollection::class);
109
        foreach ($commandClasses as $commandClass) {
110
            $commandCollector->add($commandClass);
111
        }
112
    }
113
}