ViewServiceProvider::loadConfigs()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
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