Completed
Push — master ( 12a2e2...71a5fb )
by Nicolas
12s
created

MenusServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 91.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
lcom 2
cbo 4
dl 0
loc 84
ccs 33
cts 36
cp 0.9167
rs 10
c 2
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A registerMenusFile() 0 6 2
A register() 0 8 1
A provides() 0 4 1
A registerNamespaces() 0 15 1
A registerHtmlPackage() 0 11 1
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 31
    public function boot()
21
    {
22 31
        $this->registerNamespaces();
23 31
        $this->registerMenusFile();
24 31
    }
25
26
    /**
27
     * Require the menus file if that file is exists.
28
     */
29 31
    public function registerMenusFile()
30
    {
31 31
        if (file_exists($file = app_path('Support/menus.php'))) {
32
            require $file;
33
        }
34 31
    }
35
36
    /**
37
     * Register the service provider.
38
     */
39 31
    public function register()
40
    {
41 31
        $this->registerHtmlPackage();
42
43 31
        $this->app->singleton('menus', function ($app) {
44
            return new Menu($app['view'], $app['config']);
45 31
        });
46 31
    }
47
48
    /**
49
     * Register "iluminate/html" package.
50
     */
51 31
    private function registerHtmlPackage()
52
    {
53 31
        $this->app->register('Collective\Html\HtmlServiceProvider');
54
55
        $aliases = [
56 31
            'HTML' => 'Collective\Html\HtmlFacade',
57 31
            'Form' => 'Collective\Html\FormFacade',
58 31
        ];
59
60 31
        AliasLoader::getInstance($aliases)->register();
61 31
    }
62
63
    /**
64
     * Get the services provided by the provider.
65
     *
66
     * @return array
67
     */
68 1
    public function provides()
69
    {
70 1
        return ['menus'];
71
    }
72
73
    /**
74
     * Register package's namespaces.
75
     */
76 31
    protected function registerNamespaces()
77
    {
78 31
        $configPath = __DIR__ . '/../config/config.php';
79 31
        $viewsPath = __DIR__ . '/../views';
80 31
        $this->mergeConfigFrom($configPath, 'menus');
81 31
        $this->loadViewsFrom($viewsPath, 'menus');
82
83 31
        $this->publishes([
84 31
            $configPath => config_path('menus.php'),
85 31
        ], 'config');
86
87 31
        $this->publishes([
88 31
            $viewsPath => base_path('resources/views/vendor/nwidart/menus'),
89 31
        ], 'views');
90 31
    }
91
}
92