Completed
Push — master ( 5e1e13...f15dc3 )
by Nicolas
03:21
created

MenusServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Nwidart\Menus;
4
5
use Illuminate\Foundation\AliasLoader;
6
use Illuminate\Support\ServiceProvider;
7
8
class MenusServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Indicates if loading of the provider is deferred.
12
     *
13
     * @var bool
14
     */
15
    protected $defer = true;
16
17
    /**
18
     * Bootstrap the application events.
19
     */
20
    public function boot()
21
    {
22
        $this->registerNamespaces();
23
        $this->registerMenusFile();
24
    }
25
26
    /**
27
     * Require the menus file if that file is exists.
28
     */
29
    public function registerMenusFile()
30
    {
31
        if (file_exists($file = app_path('Support/menus.php'))) {
32
            require $file;
33
        }
34
    }
35
36
    /**
37
     * Register the service provider.
38
     */
39
    public function register()
40
    {
41
        $this->registerHtmlPackage();
42
43
        $this->app->singleton('menus', function ($app)
44
        {
45
            return new Menu($app['view'], $app['config']);
46
        });
47
    }
48
49
    /**
50
     * Register "iluminate/html" package.
51
     */
52
    private function registerHtmlPackage()
53
    {
54
        $this->app->register('Collective\Html\HtmlServiceProvider');
55
56
        $aliases = [
57
            'HTML' => 'Collective\Html\HtmlFacade',
58
            'Form' => 'Collective\Html\FormFacade',
59
        ];
60
61
        AliasLoader::getInstance($aliases)->register();
62
    }
63
64
    /**
65
     * Get the services provided by the provider.
66
     *
67
     * @return array
68
     */
69 1
    public function provides()
70
    {
71 1
        return ['menus'];
72
    }
73
74
    /**
75
     * Register package's namespaces.
76
     */
77
    protected function registerNamespaces()
78
    {
79
        $configPath = __DIR__ . '/../config/config.php';
80
        $viewsPath = __DIR__ . '/../views';
81
        $this->mergeConfigFrom($configPath, 'menus');
82
        $this->loadViewsFrom($viewsPath, 'menus');
83
84
        $this->publishes([
85
            $configPath => config_path('menus.php'),
86
        ], 'config');
87
88
        $this->publishes([
89
            $viewsPath => base_path('resources/views/vendor/nwidart/menus'),
90
        ], 'views');
91
    }
92
}
93