1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ElfSundae\Apps; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Arr; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
|
8
|
|
|
class AppsServiceProvider extends ServiceProvider |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Bootstrap the service provider. |
12
|
|
|
* |
13
|
|
|
* @return void |
14
|
|
|
*/ |
15
|
6 |
|
public function boot() |
16
|
|
|
{ |
17
|
6 |
|
(new MacroRegistrar)->registerMacros($this->app); |
18
|
|
|
|
19
|
6 |
|
$this->publishAssets(); |
20
|
6 |
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Publish assets from package. |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
6 |
|
protected function publishAssets() |
28
|
|
|
{ |
29
|
6 |
|
if ($this->app->runningInConsole()) { |
30
|
6 |
|
$this->publishes([ |
31
|
6 |
|
__DIR__.'/../config/apps.php' => config_path('apps.php'), |
32
|
6 |
|
], 'laravel-apps'); |
33
|
|
|
} |
34
|
6 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Register the service provider. |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
8 |
|
public function register() |
42
|
|
|
{ |
43
|
8 |
|
$this->setupAssets(); |
44
|
|
|
|
45
|
8 |
|
$this->registerAppManager(); |
46
|
|
|
|
47
|
8 |
|
$this->registerConfiguredProviders(); |
48
|
|
|
|
49
|
8 |
|
$this->setupConfiguration(); |
50
|
8 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Setup package assets. |
54
|
|
|
* |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
8 |
|
protected function setupAssets() |
58
|
|
|
{ |
59
|
8 |
|
$this->mergeConfigFrom(__DIR__.'/../config/apps.php', 'apps'); |
60
|
8 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Register app manager singleton. |
64
|
|
|
* |
65
|
|
|
* @return void |
66
|
|
|
*/ |
67
|
|
|
protected function registerAppManager() |
68
|
|
|
{ |
69
|
8 |
|
$this->app->singleton('apps', function ($app) { |
70
|
8 |
|
return new AppManager($app); |
71
|
8 |
|
}); |
72
|
|
|
|
73
|
8 |
|
$this->app->alias('apps', AppManager::class); |
74
|
8 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Register the configured service providers. |
78
|
|
|
* |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
8 |
|
protected function registerConfiguredProviders() |
82
|
|
|
{ |
83
|
8 |
|
$providers = $this->app['config']->get('apps.providers', []); |
84
|
|
|
|
85
|
8 |
|
if ($this->app->runningInConsole()) { |
86
|
6 |
|
$providers = array_unique(Arr::flatten($providers)); |
87
|
|
|
} else { |
88
|
2 |
|
$providers = (array) Arr::get($providers, $this->app['apps']->id()); |
89
|
|
|
} |
90
|
|
|
|
91
|
8 |
|
array_walk($providers, function ($p) { |
92
|
2 |
|
$this->app->register($p); |
93
|
8 |
|
}); |
94
|
8 |
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Setup application configurations. |
98
|
|
|
* |
99
|
|
|
* @return void |
100
|
|
|
*/ |
101
|
8 |
|
protected function setupConfiguration() |
102
|
|
|
{ |
103
|
8 |
|
$booting = $this->app->isBooted() ? 'booted' : 'booting'; |
104
|
|
|
|
105
|
8 |
|
$this->app->$booting(function ($app) { |
106
|
6 |
|
$config = $app['config']; |
107
|
|
|
|
108
|
6 |
|
if (! $app->configurationIsCached()) { |
109
|
6 |
|
$config->set($config->get('apps.config.default', [])); |
110
|
|
|
} |
111
|
|
|
|
112
|
6 |
|
if ($appId = $app['apps']->id()) { |
113
|
5 |
|
$config->set($config->get('apps.config.'.$appId, [])); |
114
|
|
|
} |
115
|
8 |
|
}); |
116
|
8 |
|
} |
117
|
|
|
} |
118
|
|
|
|