Completed
Push — master ( de96d1...814281 )
by Elf
01:16
created

AppsServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 10
Bugs 0 Features 0
Metric Value
c 10
b 0
f 0
dl 0
loc 86
ccs 31
cts 31
cp 1
rs 10
wmc 9
lcom 1
cbo 4

6 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A publishAssets() 0 8 2
A register() 0 8 1
A setupAssets() 0 4 1
A registerAppManager() 0 8 1
A setupConfiguration() 0 14 3
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 2
            $this->publishes([
30 2
                __DIR__.'/../config/apps.php' => config_path('apps.php'),
31 2
            ], 'laravel-apps');
32
        }
33 2
    }
34
35
    /**
36
     * Register the service provider.
37
     *
38
     * @return void
39
     */
40 2
    public function register()
41
    {
42 2
        $this->setupAssets();
43
44 2
        $this->registerAppManager();
45
46 2
        $this->setupConfiguration();
47 2
    }
48
49
    /**
50
     * Setup package assets.
51
     *
52
     * @return void
53
     */
54 2
    protected function setupAssets()
55
    {
56 2
        $this->mergeConfigFrom(__DIR__.'/../config/apps.php', 'apps');
57 2
    }
58
59
    /**
60
     * Register app manager singleton.
61
     *
62
     * @return void
63
     */
64 2
    protected function registerAppManager()
65
    {
66
        $this->app->singleton('apps', function ($app) {
67 2
            return new AppManager($app);
68 2
        });
69
70 2
        $this->app->alias('apps', AppManager::class);
71 2
    }
72
73
    /**
74
     * Setup application configurations.
75
     *
76
     * @return void
77
     */
78
    protected function setupConfiguration()
79
    {
80 2
        $this->app->booting(function ($app) {
81 1
            $config = $app['config'];
82
83 1
            if (! $app->configurationIsCached()) {
84 1
                $config->set($config->get('apps.config.default', []));
85
            }
86
87 1
            if ($appId = $app['apps']->id()) {
88 1
                $config->set($config->get('apps.config.'.$appId, []));
89
            }
90 2
        });
91 2
    }
92
}
93