Completed
Push — master ( f25e5f...510f3d )
by Elf
03:28 queued 02:11
created

AppsServiceProvider   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 95.65%

Importance

Changes 12
Bugs 0 Features 0
Metric Value
c 12
b 0
f 0
dl 0
loc 110
ccs 44
cts 46
cp 0.9565
rs 10
wmc 12
lcom 1
cbo 5

7 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A register() 0 10 1
A setupAssets() 0 4 1
A registerAppManager() 0 8 1
A registerConfiguredProviders() 0 14 2
A publishAssets() 0 8 2
A setupConfiguration() 0 16 4
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 5
    public function boot()
16
    {
17 5
        (new MacroRegistrar)->registerMacros($this->app);
18
19 5
        $this->publishAssets();
20 5
    }
21
22
    /**
23
     * Publish assets from package.
24
     *
25
     * @return void
26
     */
27 5
    protected function publishAssets()
28
    {
29 5
        if ($this->app->runningInConsole()) {
30 5
            $this->publishes([
31 5
                __DIR__.'/../config/apps.php' => config_path('apps.php'),
32 5
            ], 'laravel-apps');
33 5
        }
34 5
    }
35
36
    /**
37
     * Register the service provider.
38
     *
39
     * @return void
40
     */
41 5
    public function register()
42
    {
43 5
        $this->setupAssets();
44
45 5
        $this->registerAppManager();
46
47 5
        $this->registerConfiguredProviders();
48
49 5
        $this->setupConfiguration();
50 5
    }
51
52
    /**
53
     * Setup package assets.
54
     *
55
     * @return void
56
     */
57 5
    protected function setupAssets()
58
    {
59 5
        $this->mergeConfigFrom(__DIR__.'/../config/apps.php', 'apps');
60 5
    }
61
62
    /**
63
     * Register app manager singleton.
64
     *
65
     * @return void
66
     */
67 5
    protected function registerAppManager()
68
    {
69
        $this->app->singleton('apps', function ($app) {
70 5
            return new AppManager($app);
71 5
        });
72
73 5
        $this->app->alias('apps', AppManager::class);
74 5
    }
75
76
    /**
77
     * Register the configured service providers.
78
     *
79
     * @return void
80
     */
81 5
    protected function registerConfiguredProviders()
82
    {
83 5
        $providers = $this->app['config']->get('apps.providers', []);
84
85 5
        if ($this->app->runningInConsole()) {
86 5
            $providers = array_unique(Arr::flatten($providers));
87 5
        } 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 5
        });
94 5
    }
95
96
    /**
97
     * Setup application configurations.
98
     *
99
     * @return void
100
     */
101 5
    protected function setupConfiguration()
102
    {
103 5
        $booting = $this->app->isBooted() ? 'booted' : 'booting';
0 ignored issues
show
Bug introduced by
The method isBooted() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean booted()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
104
105 5
        $this->app->$booting(function ($app) {
106 5
            $config = $app['config'];
107
108 5
            if (! $app->configurationIsCached()) {
109 5
                $config->set($config->get('apps.config.default', []));
110 5
            }
111
112 5
            if ($appId = $app['apps']->id()) {
113 4
                $config->set($config->get('apps.config.'.$appId, []));
114 4
            }
115 5
        });
116 5
    }
117
}
118