LaravelQuickMenusServiceProvider::boot()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 48
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 4

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 23
c 3
b 0
f 1
dl 0
loc 48
ccs 21
cts 21
cp 1
rs 9.552
cc 4
nc 4
nop 0
crap 4
1
<?php
2
3
namespace DavideCasiraghi\LaravelQuickMenus;
4
5
use Carbon\Carbon;
6
use Illuminate\Support\ServiceProvider;
7
8
class LaravelQuickMenusServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     */
13 25
    public function boot()
14
    {
15
        /*
16
         * Optional methods to load your package assets
17
         */
18 25
        $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-quick-menus');
19 25
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-quick-menus');
20 25
        $this->loadRoutesFrom(__DIR__.'/../routes/web.php');
21 25
        $this->app['router']->aliasMiddleware('admin', \DavideCasiraghi\LaravelQuickMenus\Http\Middleware\Admin::class);
22
23 25
        if ($this->app->runningInConsole()) {
24 25
            $this->publishes([
25 25
                __DIR__.'/../config/config.php' => config_path('laravel-quick-menus.php'),
26 25
            ], 'config');
27
28
            // Publishing the views.
29 25
            $this->publishes([
30 25
                __DIR__.'/../resources/views' => resource_path('views/vendor/laravel-quick-menus'),
31 25
            ], 'views');
32
33
            // Publishing assets.
34
            /*$this->publishes([
35
                __DIR__.'/../resources/assets' => public_path('vendor/laravel-quick-menus'),
36
            ], 'assets');*/
37
38
            // Publishing the translation files.
39 25
            $this->publishes([
40 25
                __DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-quick-menus'),
41 25
            ], 'lang');
42
43
            // Registering package commands.
44
            // $this->commands([]);
45
46
            /* - Migrations -
47
               create a migration instance for each .php.stub file eg.
48
               create_continents_table.php.stub --->  2019_04_28_190434761474_create_continents_table.php
49
            */
50
            $migrations = [
51 25
                'CreateMenusTable' => 'create_menus_table',
52
                'CreateMenuItemsTable' => 'create_menu_items_table',
53
                'CreateMenuItemTranslationsTable' => 'create_menu_item_translations_table',
54
            ];
55
56 25
            foreach ($migrations as $migrationFunctionName => $migrationFileName) {
57 25
                if (! class_exists($migrationFunctionName)) {
58 1
                    $this->publishes([
59 1
                        __DIR__.'/../database/migrations/'.$migrationFileName.'.php.stub' => database_path('migrations/'.Carbon::now()->format('Y_m_d_Hmsu').'_'.$migrationFileName.'.php'),
60 25
                    ], 'migrations');
61
                }
62
            }
63
        }
64 25
    }
65
66
    /**
67
     * Register the application services.
68
     */
69 25
    public function register()
70
    {
71
        // Automatically apply the package configuration
72 25
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-quick-menus');
73
74
        // Register the main class to use with the facade
75
        $this->app->singleton('laravel-quick-menus', function () {
76
            return new LaravelQuickMenus;
77 25
        });
78 25
    }
79
}
80