Completed
Push — master ( e52e2c...9baf6c )
by Oleg
08:13
created

MenuServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Malezha\Menu;
4
5
use Illuminate\Contracts\Container\Container;
6
use Illuminate\Support\ServiceProvider;
7
use Malezha\Menu\Contracts\Attributes as AttributesContract;
8
use Malezha\Menu\Contracts\Builder as BuilderContract;
9
use Malezha\Menu\Contracts\Group as GroupContract;
10
use Malezha\Menu\Contracts\Item as ItemContract;
11
use Malezha\Menu\Contracts\Link as LinkContract;
12
use Malezha\Menu\Contracts\Menu as MenuContract;
13
use Malezha\Menu\Entity\Attributes;
14
use Malezha\Menu\Entity\Builder;
15
use Malezha\Menu\Entity\Group;
16
use Malezha\Menu\Entity\Item;
17
use Malezha\Menu\Entity\Link;
18
19
/**
20
 * Class MenuServiceProvider
21
 * @package Malezha\Menu
22
 */
23
class MenuServiceProvider extends ServiceProvider
24
{
25
    /**
26
     * Indicates if loading of the provider is deferred.
27
     *
28
     * @var bool
29
     */
30
    protected $defer = false;
31
32
    /**
33
     * Bootstrap the application services.
34
     *
35
     * @return void
36
     */
37 25
    public function boot()
38
    {
39 25
        $this->loadViewsFrom(__DIR__ . '/../views', 'menu');
40
41 25
        $this->publishes([
42 25
            __DIR__ . '/../views' => base_path('resources/views/vendor/menu'),
43 25
            __DIR__ . '/../config/menu.php' => config_path('menu.php'),
44 25
        ]);
45 25
    }
46
47
    /**
48
     * Register the application services.
49
     *
50
     * @return void
51
     */
52 25
    public function register()
53
    {
54 25
        $this->registerAttributes();
55 25
        $this->registerLink();
56 25
        $this->registerBuilder();
57 25
        $this->registerItem();
58 25
        $this->registerGroup();
59 25
        $this->registerSingleton();
60
61 25
        $this->mergeConfigFrom(__DIR__ . '/../config/menu.php', 'menu');
62 25
    }
63
64 25
    protected function registerSingleton()
65 25
    {
66 25
        $this->app->singleton('menu.instance', function (Container $app) {
67 25
            return new Menu($app);
68 25
        });
69 25
        $this->app->alias(MenuContract::class, 'menu.instance');
70 25
    }
71
72 25
    protected function registerBuilder()
73
    {
74 25
        $this->app->bind('menu.builder', Builder::class);
75 25
        $this->app->alias('menu.builder', BuilderContract::class);
76 25
    }
77
78 25
    protected function registerGroup()
79
    {
80 25
        $this->app->bind('menu.group', Group::class);
81 25
        $this->app->alias('menu.group', GroupContract::class);
82 25
    }
83
84 25
    protected function registerItem()
85
    {
86 25
        $this->app->bind('menu.item', Item::class);
87 25
        $this->app->alias('menu.item', ItemContract::class);
88 25
    }
89
90 25
    protected function registerLink()
91
    {
92 25
        $this->app->bind('menu.link', Link::class);
93 25
        $this->app->alias('menu.link', LinkContract::class);
94 25
    }
95
96 25
    protected function registerAttributes()
97
    {
98 25
        $this->app->bind('menu.attributes', Attributes::class);
99 25
        $this->app->alias('menu.attributes', AttributesContract::class);
100 25
    }
101
102
    /**
103
     * Get the services provided by the provider.
104
     *
105
     * @return array
106
     */
107
    public function provides()
108
    {
109
        return [];
110
    }
111
}
112