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\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
|
|
|
/** |
21
|
|
|
* Application config. |
22
|
|
|
* |
23
|
|
|
* @var MutableConfig |
24
|
|
|
*/ |
25
|
|
|
private $config; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Container instance. |
29
|
|
|
* |
30
|
|
|
* @var Container |
31
|
|
|
*/ |
32
|
|
|
private $container; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* AbstractServiceProvider constructor. |
36
|
|
|
* |
37
|
|
|
* @param Container $container |
38
|
|
|
* @param MutableConfig $mutableConfig |
39
|
|
|
*/ |
40
|
|
|
public function __construct(Container $container, MutableConfig $mutableConfig) |
41
|
|
|
{ |
42
|
|
|
$this->container = $container; |
43
|
|
|
$this->config = $mutableConfig; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @inheritdoc |
48
|
|
|
*/ |
49
|
|
|
public function boot() |
50
|
|
|
{ |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return MutableConfig |
55
|
|
|
*/ |
56
|
|
|
protected function config(): MutableConfig |
57
|
|
|
{ |
58
|
|
|
return $this->config; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return Container |
63
|
|
|
*/ |
64
|
|
|
protected function container(): Container |
65
|
|
|
{ |
66
|
|
|
return $this->container; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return Kernel |
71
|
|
|
*/ |
72
|
|
|
protected function kernel(): Kernel |
73
|
|
|
{ |
74
|
|
|
return $this->container()->get(Kernel::class); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Merges config params from service provider with the global configuration. |
79
|
|
|
* |
80
|
|
|
* @param string[] ...$configFiles |
81
|
|
|
*/ |
82
|
|
|
protected function loadConfigFromFiles(string ...$configFiles) |
83
|
|
|
{ |
84
|
|
|
foreach ($configFiles as $configFile) { |
85
|
|
|
$this->config->merge(require $configFile); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Registers commands exposed by service provider. |
91
|
|
|
* |
92
|
|
|
* @param string[] ...$commandClasses |
93
|
|
|
*/ |
94
|
|
|
protected function provideCommands(string ...$commandClasses) |
95
|
|
|
{ |
96
|
|
|
/** @var CommandCollection $commandCollector */ |
97
|
|
|
$commandCollector = $this->container->get(CommandCollection::class); |
98
|
|
|
foreach ($commandClasses as $commandClass) { |
99
|
|
|
$commandCollector->add($commandClass); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return RouteCollection |
105
|
|
|
*/ |
106
|
|
|
protected function routes(): RouteCollection |
107
|
|
|
{ |
108
|
|
|
return $this->container()->get(RouteCollection::class); |
109
|
|
|
} |
110
|
|
|
} |