Completed
Push — master ( a86d17...8d920c )
by Davide
08:03 queued 03:47
created

LaravelEventsCalendarServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 23
dl 0
loc 75
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 54 4
A register() 0 8 1
1
<?php
2
3
namespace DavideCasiraghi\LaravelEventsCalendar;
4
5
use Carbon\Carbon;
6
use Illuminate\Support\ServiceProvider;
7
8
class LaravelEventsCalendarServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     */
13
    public function boot()
14
    {
15
        /*
16
         * Optional methods to load your package assets
17
         */
18
        // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-events-calendar');
19
        // $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-events-calendar');
20
        // $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
21
        // $this->loadRoutesFrom(__DIR__.'/routes.php');
22
23
        if ($this->app->runningInConsole()) {
24
            $this->publishes([
25
                __DIR__.'/../config/config.php' => config_path('laravel-events-calendar.php'),
26
            ], 'config');
27
28
            // Publishing the views.
29
            /*$this->publishes([
30
                __DIR__.'/../resources/views' => resource_path('views/vendor/laravel-events-calendar'),
31
            ], 'views');*/
32
33
            // Publishing assets.
34
            /*$this->publishes([
35
                __DIR__.'/../resources/assets' => public_path('vendor/laravel-events-calendar'),
36
            ], 'assets');*/
37
38
            // Publishing the translation files.
39
            /*$this->publishes([
40
                __DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-events-calendar'),
41
            ], '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
                     'CreateQuotesTable' => 'create_continents_table',
52
                     'CreateCountriesTable' => 'create_countries_table',
53
                     'CreateEventHasOrganizersTable' => 'create_event_has_organizers_table',
54
                     'CreateEventHasTeachersTable' => 'create_event_has_teachers_table',
55
                     'CreateEventsTable' => 'create_events_table',
56
                     'CreateOrganizersTable' => 'create_organizers_table',
57
                     'CreateEventCategoriesTable' => 'event_categories_table',
58
                     'CreateEventRepetitionsTable' => 'event_repetitions_table',
59
                     'CreateEventVenuesTable' => 'event_venues',
60
                 ];
61
62
            foreach ($migrations as $migrationFunctionName => $migrationFileName) {
63
                if (! class_exists($migrationFunctionName)) {
64
                    $this->publishes([
65
                            __DIR__.'/../database/migrations/'.$migrationFileName.'.php.stub' => database_path('migrations/'.Carbon::now()->format('Y_m_d_Hmsu').'_'.$migrationFileName.'.php'),
66
                        ], 'migrations');
67
                }
68
            }
69
        }
70
    }
71
72
    /**
73
     * Register the application services.
74
     */
75
    public function register()
76
    {
77
        // Automatically apply the package configuration
78
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-events-calendar');
79
80
        // Register the main class to use with the facade
81
        $this->app->singleton('laravel-events-calendar', function () {
82
            return new LaravelEventsCalendar;
83
        });
84
    }
85
}
86