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