Completed
Push — master ( 8272d6...f25e5f )
by Elf
03:24 queued 13s
created

AppsServiceProvider::setupAssets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 3
b 0
f 0
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 2
    protected function setupConfiguration()
102
    {
103 2
        $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 2
        $this->app->$booting(function ($app) {
106 2
            $config = $app['config'];
107
108 2
            if (! $app->configurationIsCached()) {
109 2
                $config->set($config->get('apps.config.default', []));
110
            }
111
112 2
            if ($appId = $app['apps']->id()) {
113 1
                $config->set($config->get('apps.config.'.$appId, []));
114
            }
115 2
        });
116 2
    }
117
}
118