ThemeServiceProvider   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 57
rs 10
c 6
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 7 1
A setActiveTheme() 0 16 4
A inAdministration() 0 6 2
A registerAllThemes() 0 8 2
1
<?php namespace Modules\Setting\Providers;
2
3
use Illuminate\Support\ServiceProvider;
4
5
class ThemeServiceProvider extends ServiceProvider
6
{
7
    /**
8
     * Register the service provider.
9
     * @return void
10
     */
11
    public function register()
12
    {
13
        $this->app->booted(function () {
14
            $this->registerAllThemes();
15
            $this->setActiveTheme();
16
        });
17
    }
18
19
    /**
20
     * Set the active theme based on the settings
21
     */
22
    private function setActiveTheme()
23
    {
24
        if ($this->app->runningInConsole() || ! app('asgard.isInstalled')) {
25
            return;
26
        }
27
28
        if ($this->inAdministration()) {
29
            $themeName = $this->app['config']->get('asgard.core.core.admin-theme');
30
31
            return $this->app['stylist']->activate($themeName, true);
32
        }
33
34
        $themeName = $this->app['setting.settings']->get('core::template', null, 'Flatly');
35
36
        return $this->app['stylist']->activate($themeName, true);
37
    }
38
39
    /**
40
     * Check if we are in the administration
41
     * @return bool
42
     */
43
    private function inAdministration()
44
    {
45
        $segment = config('laravellocalization.hideDefaultLocaleInURL', false) ? 1 : 2;
46
47
        return $this->app['request']->segment($segment) === $this->app['config']->get('asgard.core.core.admin-prefix');
48
    }
49
50
    /**
51
     * Register all themes with activating them
52
     */
53
    private function registerAllThemes()
54
    {
55
        $directories = $this->app['files']->directories(config('stylist.themes.paths', [base_path('/Themes')])[0]);
56
57
        foreach ($directories as $directory) {
58
            $this->app['stylist']->registerPath($directory);
59
        }
60
    }
61
}
62