JarvisFoundationServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\Providers;
4
5
use Hechoenlaravel\JarvisFoundation\Menu\MenuService;
6
use Spatie\Menu\Laravel\Html;
7
use Spatie\Menu\Laravel\Menu;
8
use Illuminate\Support\Facades\Auth;
9
use Illuminate\Foundation\AliasLoader;
10
use Illuminate\Support\ServiceProvider;
11
12
/**
13
 * Class JarvisFoundationServiceProvider
14
 * @package Hechoenlaravel\JarvisFoundation\Providers
15
 */
16
class JarvisFoundationServiceProvider extends ServiceProvider
17
{
18
19
    /**
20
     * Service providers to load
21
     * @var array
22
     */
23
    protected $providers = [
24
        \Hechoenlaravel\JarvisPlatformUi\Providers\JarvisPlatformUiServiceProvider::class,
25
        \Joselfonseca\LaravelTactician\Providers\LaravelTacticianServiceProvider::class,
26
        \Hechoenlaravel\JarvisFoundation\Providers\FieldsServiceProvider::class,
27
        \Hechoenlaravel\JarvisFoundation\Providers\EventServiceProvider::class,
28
        \Styde\Html\HtmlServiceProvider::class,
29
        \Nwidart\Modules\LaravelModulesServiceProvider::class,
30
        \Spatie\Permission\PermissionServiceProvider::class,
31
        \Laracasts\Utilities\JavaScript\JavaScriptServiceProvider::class,
32
        \UxWeb\SweetAlert\SweetAlertServiceProvider::class,
33
        \Yajra\DataTables\DataTablesServiceProvider::class,
34
        \Hechoenlaravel\JarvisFoundation\Providers\ViewComposersServiceProvider::class,
35
        \Maatwebsite\Excel\ExcelServiceProvider::class,
36
        \Intervention\Image\ImageServiceProvider::class,
37
        \Yajra\DataTables\HtmlServiceProvider::class,
38
        \Spatie\Backup\BackupServiceProvider::class,
39
        \Sentry\SentryLaravel\SentryLaravelServiceProvider::class,
40
        \Hechoenlaravel\JarvisMenus\MenusServiceProvider::class
41
    ];
42
43
    /**
44
     * @var array
45
     */
46
    protected $aliases = [
47
        'Module' => \Nwidart\Modules\Facades\Module::class,
48
        'Uuid' => \Webpatser\Uuid\Uuid::class,
49
        'SweetAlert' => \UxWeb\SweetAlert\SweetAlert::class,
50
        'Datatables' => \Yajra\Datatables\Datatables::class,
51
        'Excel' => \Maatwebsite\Excel\Facades\Excel::class,
52
        'Sentry' => \Sentry\SentryLaravel\SentryFacade::class,
53
    ];
54
55
    /**
56
     * Perform post-registration booting of services.
57
     *
58
     * @return void
59
     */
60
    public function boot()
61
    {
62
        $this->publishes([
63
            __DIR__.'/../../resources/assets' => public_path('vendor/jplatform'),
64
        ], 'public');
65
        $this->registerMenus();
66
    }
67
68
    /**
69
     * Register the service provider.
70
     *
71
     * @return void
72
     */
73
    public function register()
74
    {
75
        $this->registerOtherProviders()->registerAliases();
76
        $this->loadViewsFrom(__DIR__.'/../../resources/views', 'jarvisPlatform');
77
        $this->loadRoutes();
78
    }
79
80
    /**
81
     * Register other Service Providers
82
     * @return $this
83
     */
84
    private function registerOtherProviders()
85
    {
86
        foreach ($this->providers as $provider) {
87
            $this->app->register($provider);
88
        }
89
        return $this;
90
    }
91
92
    /**
93
     * Register some Aliases
94
     * @return $this
95
     */
96
    protected function registerAliases()
97
    {
98
        foreach ($this->aliases as $alias => $original) {
99
            AliasLoader::getInstance()->alias($alias, $original);
100
        }
101
        return $this;
102
    }
103
104
    /**
105
     * @return $this
106
     */
107
    protected function loadRoutes()
108
    {
109
        require_once __DIR__.'/../Http/routes.php';
110
        return $this;
111
    }
112
113
    /**
114
     * @return $this
115
     */
116
    protected function registerMenus()
117
    {
118
        if(!app('menu')->instance('sidebar')) {
119
            app('menu')->create('sidebar', function ($menu) {
120
                $menu->enableOrdering();
121
            });
122
            $this->app->singleton('menu.service', function(){
123
                return new MenuService();
124
            });
125
        }
126
    }
127
}
128