ViewServiceProvider   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 14 3
A boot() 0 5 1
A loadConfigs() 0 10 1
A loadViews() 0 6 2
A provides() 0 4 1
1
<?php
2
3
namespace JumpGate\ViewResolution\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
use JumpGate\ViewResolution\Builders\View;
7
use JumpGate\ViewResolution\Collectors\AutoViewCollector;
8
9
class ViewServiceProvider extends ServiceProvider
10
{
11
    protected $defer = true;
12
13
    /**
14
     * Register the HTML builder instance.
15
     *
16
     * @return void
17
     */
18
    public function register()
19
    {
20
        $this->app->singleton('viewResolver', function ($app) {
21
            return $app->make(View::class);
22
        });
23
24
        if (checkDebugbar()) {
25
            $debugbar = $this->app['debugbar'];
26
27
            if ($debugbar->shouldCollect('auto_views')) {
28
                $debugbar->addCollector(new AutoViewCollector());
29
            }
30
        }
31
    }
32
33
    public function boot()
34
    {
35
        $this->loadConfigs();
36
        $this->loadViews();
37
    }
38
39
    /**
40
     * Allow configs to be published but use the included by default.
41
     */
42
    protected function loadConfigs()
43
    {
44
        $this->publishes([
45
            __DIR__ . '/../../../config/view-resolution.php' => config_path('jumpgate/view-resolution.php'),
46
        ]);
47
48
        $this->mergeConfigFrom(
49
            __DIR__ . '/../../../config/view-resolution.php', 'jumpgate.view-resolution'
50
        );
51
    }
52
53
    /**
54
     * Register views
55
     *
56
     * @return void
57
     */
58
    protected function loadViews()
59
    {
60
        if ($this->app['config']->get('jumpgate.view-resolution.load_layout')) {
61
            $this->app['view']->addLocation(__DIR__ . '/../../../views');
62
        }
63
    }
64
65
    /**
66
     * Get the services provided by the provider.
67
     *
68
     * @return array
69
     */
70
    public function provides()
71
    {
72
        return ['viewResolver'];
73
    }
74
}
75