Completed
Push — master ( 639f1d...4ccc94 )
by Nicolas
12:26
created

MenusServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 91.67%

Importance

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

6 Methods

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