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