|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Consigliere\Components; |
|
4
|
|
|
|
|
5
|
|
|
use Consigliere\Components\Providers\BootstrapServiceProvider; |
|
6
|
|
|
use Consigliere\Components\Providers\ConsoleServiceProvider; |
|
7
|
|
|
use Consigliere\Components\Providers\ContractsServiceProvider; |
|
8
|
|
|
use Consigliere\Components\Support\Stub; |
|
9
|
|
|
|
|
10
|
|
|
class ServiceProvider extends \Illuminate\Support\ServiceProvider |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Indicates if loading of the provider is deferred. |
|
14
|
|
|
* |
|
15
|
|
|
* @var bool |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $defer = false; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Booting the package. |
|
21
|
|
|
*/ |
|
22
|
|
|
public function boot() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->registerNamespaces(); |
|
25
|
|
|
|
|
26
|
|
|
$this->registerComponents(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Register all components. |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function registerComponents() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->app->register(BootstrapServiceProvider::class); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Register the service provider. |
|
39
|
|
|
*/ |
|
40
|
|
|
public function register() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->registerServices(); |
|
43
|
|
|
$this->setupStubPath(); |
|
44
|
|
|
$this->registerProviders(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Setup stub path. |
|
49
|
|
|
*/ |
|
50
|
|
|
public function setupStubPath() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->app->booted(function($app) { |
|
53
|
|
|
Stub::setBasePath(__DIR__ . '/Commands/stubs'); |
|
54
|
|
|
|
|
55
|
|
|
if ($app['components']->config('stubs.enabled') === true) { |
|
56
|
|
|
Stub::setBasePath($app['components']->config('stubs.path')); |
|
57
|
|
|
} |
|
58
|
|
|
}); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Register package's namespaces. |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function registerNamespaces() |
|
65
|
|
|
{ |
|
66
|
|
|
$configPath = __DIR__ . '/../config/config.php'; |
|
67
|
|
|
$this->mergeConfigFrom($configPath, 'components'); |
|
68
|
|
|
$this->publishes([$configPath => config_path('components.php')], 'config'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Register the service provider. |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function registerServices() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->app->singleton('components', function($app) { |
|
77
|
|
|
$path = $app['config']->get('components.paths.components'); |
|
78
|
|
|
|
|
79
|
|
|
return new Repository($app, $path); |
|
80
|
|
|
}); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get the services provided by the provider. |
|
85
|
|
|
* |
|
86
|
|
|
* @return array |
|
87
|
|
|
*/ |
|
88
|
|
|
public function provides() |
|
89
|
|
|
{ |
|
90
|
|
|
return ['components']; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Register providers. |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function registerProviders() |
|
97
|
|
|
{ |
|
98
|
|
|
$this->app->register(ConsoleServiceProvider::class); |
|
99
|
|
|
$this->app->register(ContractsServiceProvider::class); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|