Completed
Push — master ( 22d43d...584465 )
by Elf
07:08
created

SupportServiceProvider   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 30
Bugs 1 Features 0
Metric Value
wmc 11
c 30
b 1
f 0
lcom 1
cbo 3
dl 0
loc 76
ccs 0
cts 43
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 18 2
A register() 0 12 2
A setupConfiguration() 0 10 3
A configureForCurrentRequest() 0 10 4
1
<?php
2
3
namespace ElfSundae\Laravel\Support;
4
5
use Carbon\Carbon;
6
use Illuminate\Support\Str;
7
use Illuminate\Support\ServiceProvider;
8
9
class SupportServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap the application services.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'support');
19
20
        if ($this->app->runningInConsole()) {
21
            $this->publishes([
22
                __DIR__.'/../config/support.php' => config_path('support.php'),
23
            ], 'laravel-support-config');
24
25
            $this->publishes([
26
                __DIR__.'/../resources/lang' => resource_path('lang'),
27
            ], 'laravel-support-lang');
28
29
            $this->publishes([
30
                __DIR__.'/../resources/views' => resource_path('views/vendor/support'),
31
            ], 'laravel-support-views');
32
        }
33
    }
34
35
    /**
36
     * Register the application service.
37
     *
38
     * @return void
39
     */
40
    public function register()
41
    {
42
        $this->mergeConfigFrom(__DIR__.'/../config/support.php', 'support');
43
44
        $this->setupConfiguration();
45
46
        if ($this->app->runningInConsole()) {
47
            $this->commands([
48
                Console\IdeHelperGenerateCommand::class,
49
            ]);
50
        }
51
    }
52
53
    /**
54
     * Setup application configurations.
55
     *
56
     * @return void
57
     */
58
    protected function setupConfiguration()
59
    {
60
        if (! $this->app->configurationIsCached()) {
61
            if ($defaults = $this->app['config']['support.config.default']) {
62
                $this->app['config']->set($defaults);
63
            }
64
        }
65
66
        $this->configureForCurrentRequest();
67
    }
68
69
    /**
70
     * Configure application for the current request.
71
     *
72
     * @return void
73
     */
74
    protected function configureForCurrentRequest()
75
    {
76
        if (app_id() && $appConfig = $this->app['config']->get('support.config.'.app_id())) {
77
            $this->app['config']->set($appConfig);
78
        }
79
80
        if ($carbonLocale = $this->app['config']['support.carbon_locale']) {
81
            Carbon::setLocale($carbonLocale);
82
        }
83
    }
84
}
85