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

AppsServiceProvider::setupConfiguration()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 4
b 0
f 0
nc 2
nop 0
dl 0
loc 16
ccs 12
cts 12
cp 1
crap 4
rs 9.2
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