Completed
Push — master ( 14eaec...c0ed6e )
by Nicolas
06:58
created

MenusServiceProvider::registerMenusFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

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