Passed
Push — master ( 72194f...754eba )
by Alexey
05:19
created

AbstractServiceProvider::config()   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
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types = 1);
2
3
namespace Venta\ServiceProvider;
4
5
use Venta\Contracts\Config\MutableConfig;
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 MutableConfig
29
     */
30
    private $config;
31
32
    /**
33
     * Container instance.
34
     *
35
     * @var Container
36
     */
37
    private $container;
38
39
    /**
40
     * AbstractServiceProvider constructor.
41
     *
42
     * @param MutableConfig $mutableConfig
43
     * @param Container $container
44
     */
45
    public function __construct(MutableConfig $mutableConfig, Container $container)
46
    {
47
        $this->config = $mutableConfig;
48
        $this->container = $container;
49
    }
50
51
52
    /**
53
     * @inheritdoc
54
     */
55
    public static function dependencies(): array
56
    {
57
        return [];
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    final public static function name(): string
64
    {
65
        return static::$name ?: static::class;
66
    }
67
68
    /**
69
     * @inheritdoc
70
     */
71
    abstract public function boot();
72
73
    /**
74
     * @return MutableConfig
75
     */
76
    protected function config(): MutableConfig
77
    {
78
        return $this->config;
79
    }
80
81
    /**
82
     * @return Container
83
     */
84
    protected function container(): Container
85
    {
86
        return $this->container;
87
    }
88
89
    /**
90
     * @return Kernel
91
     */
92
    protected function kernel(): Kernel
93
    {
94
        return $this->container()->get(Kernel::class);
95
    }
96
97
    /**
98
     * Merges config params from service provider with the global configuration.
99
     *
100
     * @param string[] ...$configFiles
101
     */
102
    protected function loadConfigFromFiles(string ...$configFiles)
103
    {
104
        foreach ($configFiles as $configFile) {
105
            $this->config->merge(require $configFile);
106
        }
107
    }
108
109
    /**
110
     * Registers commands exposed by service provider.
111
     *
112
     * @param string[] ...$commandClasses
113
     */
114
    protected function provideCommands(string ...$commandClasses)
115
    {
116
        /** @var CommandCollection $commandCollector */
117
        $commandCollector = $this->container->get(CommandCollection::class);
118
        foreach ($commandClasses as $commandClass) {
119
            $commandCollector->add($commandClass);
120
        }
121
    }
122
}