-
Notifications
You must be signed in to change notification settings - Fork 3
/
BundlesServiceProvider.php
98 lines (84 loc) · 2.06 KB
/
BundlesServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* Author: liangwengao
* Email: wengaolng@gmail.com
* Date: 2017-01-25
* Time: 14:42
*/
namespace Awen\Bundles;
use Illuminate\Support\ServiceProvider;
class BundlesServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Booting the package.
*/
public function boot()
{
$this->mergeConfig();
$this->registerBundles();
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerServices();
$this->registerProviders();
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('bundles');
}
/**
* Setup stub path.
*/
public function registerProviders()
{
$this->app->register(__NAMESPACE__.'\\Providers\\ConsoleServiceProvider');
$this->app->bind('BundlesRepository', 'Awen\Bundles\Repositories\Repository');
}
/**
* 注册所有模块
*/
protected function registerBundles()
{
$this->app->register('Awen\Bundles\Providers\BootstrapServiceProvider');
}
/**
* 注册提供商服务
*/
protected function registerServices()
{
$this->app->singleton('bundles', function ($app) {
$root_path = $app['config']->get('bundles.root.path');
$kernel = $app['config']->get('bundles.root.kernel');
return new BundlesBootstrap($app, $kernel, $root_path);
});
}
/**
* 合并包配置文件
*/
protected function mergeConfig()
{
$config_path = __DIR__.'/src/config/config.php';
$root_path = __DIR__.'/src/config/root.php';
$this->mergeConfigFrom($config_path, 'bundles');
$this->mergeConfigFrom($root_path, 'bundles.root');
$this->publishes([
$config_path => config_path('bundles.php')
], 'bundle');
}
}