Passed
Push — master ( a6d17d...559900 )
by Alexey
05:21
created

AbstractServiceProvider::routes()   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\MutableContainer;
8
use Venta\Contracts\Kernel\Kernel;
9
use Venta\Contracts\Routing\RouteCollection;
10
use Venta\Contracts\ServiceProvider\ServiceProvider;
11
12
/**
13
 * Class AbstractServiceProvider.
14
 *
15
 * @package Venta\ServiceProvider
16
 */
17
abstract class AbstractServiceProvider implements ServiceProvider
18
{
19
    /**
20
     * Service provider name.
21
     *
22
     * @var string
23
     */
24
    protected static $name;
25
26
    /**
27
     * Application config.
28
     *
29
     * @var MutableConfig
30
     */
31
    private $config;
32
33
    /**
34
     * Container instance.
35
     *
36
     * @var MutableContainer
37
     */
38
    private $container;
39
40
    /**
41
     * AbstractServiceProvider constructor.
42
     *
43
     * @param MutableContainer $mutableContainer
44
     * @param MutableConfig $mutableConfig
45
     */
46
    public function __construct(MutableContainer $mutableContainer, MutableConfig $mutableConfig)
47
    {
48
        $this->container = $mutableContainer;
49
        $this->config = $mutableConfig;
50
    }
51
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public static function dependencies(): array
57
    {
58
        return [];
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64
    final public static function name(): string
65
    {
66
        return static::$name ?: static::class;
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72
    abstract public function boot();
73
74
    /**
75
     * @return MutableConfig
76
     */
77
    protected function config(): MutableConfig
78
    {
79
        return $this->config;
80
    }
81
82
    /**
83
     * @return MutableContainer
84
     */
85
    protected function container(): MutableContainer
86
    {
87
        return $this->container;
88
    }
89
90
    /**
91
     * @return Kernel
92
     */
93
    protected function kernel(): Kernel
94
    {
95
        return $this->container()->get(Kernel::class);
96
    }
97
98
    /**
99
     * Merges config params from service provider with the global configuration.
100
     *
101
     * @param string[] ...$configFiles
102
     */
103
    protected function loadConfigFromFiles(string ...$configFiles)
104
    {
105
        foreach ($configFiles as $configFile) {
106
            $this->config->merge(require $configFile);
107
        }
108
    }
109
110
    /**
111
     * Registers commands exposed by service provider.
112
     *
113
     * @param string[] ...$commandClasses
114
     */
115
    protected function provideCommands(string ...$commandClasses)
116
    {
117
        /** @var CommandCollection $commandCollector */
118
        $commandCollector = $this->container->get(CommandCollection::class);
119
        foreach ($commandClasses as $commandClass) {
120
            $commandCollector->add($commandClass);
121
        }
122
    }
123
124
    /**
125
     * @return RouteCollection
126
     */
127
    protected function routes(): RouteCollection
128
    {
129
        return $this->container()->get(RouteCollection::class);
130
    }
131
}