LaravelEventsCalendarServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 3
Metric Value
wmc 5
eloc 68
c 3
b 0
f 3
dl 0
loc 136
ccs 59
cts 59
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 19 1
B boot() 0 106 4
1
<?php
2
3
namespace DavideCasiraghi\LaravelEventsCalendar;
4
5
use Carbon\Carbon;
6
use DavideCasiraghi\LaravelEventsCalendar\Console\RetrieveAllGpsCoordinates;
7
use Illuminate\Support\Facades\Blade;
8
use Illuminate\Support\ServiceProvider;
9
10
class LaravelEventsCalendarServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap the application services.
14
     */
15 169
    public function boot()
16
    {
17
        /*
18
         * Optional methods to load your package assets
19
         */
20 169
        $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-events-calendar');
21 169
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-events-calendar');
22 169
        $this->loadRoutesFrom(__DIR__.'/../routes/web.php');
23
24
        // Register middleware
25
        // https://stackoverflow.com/questions/29599584/laravel-5-register-middleware-from-in-package-service-provider
26
        // https://stackoverflow.com/questions/45398875/getting-route-in-laravel-packages-middleware
27
28 169
        $this->app['router']->aliasMiddleware('admin', \DavideCasiraghi\LaravelEventsCalendar\Http\Middleware\Admin::class);
29
30 169
        if ($this->app->runningInConsole()) {
31 169
            $this->publishes([
32 169
                __DIR__.'/../config/config.php' => config_path('laravel-events-calendar.php'),
33 169
            ], 'config');
34
35
            // Publishing the views.
36 169
            $this->publishes([
37 169
                __DIR__.'/../resources/views' => resource_path('views/vendor/laravel-events-calendar'),
38 169
            ], 'views');
39
40 169
            $this->publishes([
41 169
                __DIR__.'/../resources/assets/sass' => resource_path('sass/vendor/laravel-events-calendar/'),
42 169
            ], 'sass');
43 169
            $this->publishes([
44 169
                __DIR__.'/../resources/assets/js' => resource_path('js/vendor/laravel-events-calendar/'),
45 169
            ], 'js');
46
47 169
            $this->publishes([
48 169
                __DIR__.'/../resources/assets/images' => public_path('vendor/laravel-events-calendar/images/'),
49 169
            ], 'images');
50
51
            // Publishing assets.
52
            /*$this->publishes([
53
                __DIR__.'/../resources/assets' => public_path('vendor/laravel-events-calendar'),
54
            ], 'assets');*/
55
56
            // Publishing the translation files.
57 169
            $this->publishes([
58 169
                __DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-events-calendar'),
59 169
            ], 'lang');
60
61
            // Registering package commands.
62 169
            $this->commands([
63 169
                RetrieveAllGpsCoordinates::class,
64
            ]);
65
66
            /* - Migrations -
67
               create a migration instance for each .php.stub file eg.
68
               create_continents_table.php.stub --->  2019_04_28_190434761474_create_continents_table.php
69
            */
70
            $migrations = [
71 169
                'CreateQuotesTable' => 'create_continents_table',
72
                'CreateCountriesTable' => 'create_countries_table',
73
                'CreateEventHasOrganizersTable' => 'create_event_has_organizers_table',
74
                'CreateEventHasTeachersTable' => 'create_event_has_teachers_table',
75
                'CreateEventsTable' => 'create_events_table',
76
                'CreateOrganizersTable' => 'create_organizers_table',
77
                'CreateEventCategoriesTable' => 'create_event_categories_table',
78
                'CreateEventCategoryTranslationsTable' => 'create_event_category_translations_table',
79
                'CreateEventRepetitionsTable' => 'create_event_repetitions_table',
80
                'CreateEventVenuesTable' => 'create_event_venues_table',
81
                'CreateTeachersTable' => 'create_teachers_table',
82
            ];
83
84 169
            foreach ($migrations as $migrationFunctionName => $migrationFileName) {
85 169
                if (! class_exists($migrationFunctionName)) {
86 169
                    $this->publishes([
87 169
                        __DIR__.'/../database/migrations/'.$migrationFileName.'.php.stub' => database_path('migrations/'.Carbon::now()->format('Y_m_d_Hmsu').'_'.$migrationFileName.'.php'),
88 169
                    ], 'migrations');
89
                }
90
            }
91
92
            /* Seeders */
93 169
            $this->publishes([
94 169
                __DIR__.'/../database/seeds/ContinentsTableSeeder.php' => database_path('seeds/ContinentsTableSeeder.php'),
95 169
            ], 'seed-continents');
96 169
            $this->publishes([
97 169
                __DIR__.'/../database/seeds/CountriesTableSeeder.php' => database_path('seeds/CountriesTableSeeder.php'),
98 169
            ], 'seed-countries');
99 169
            $this->publishes([
100 169
                __DIR__.'/../database/seeds/EventCategoriesTableSeeder.php' => database_path('seeds/EventCategoriesTableSeeder.php'),
101 169
            ], 'seed-event-categories');
102
        }
103
104
        /* Directives to manage the dates*/
105
        Blade::directive('date', function ($expression) {
106 1
            return "<?php echo date('d/m/Y', strtotime($expression))?>";
107 169
        });
108
        Blade::directive('date_monthname', function ($expression) {
109
            /*return "<?php echo date('d M Y', strtotime($expression))?>";*/
110 1
            return "<?php echo Carbon\Carbon::parse($expression)->isoFormat('D MMM YYYY'); ?>";
111 169
        });
112
        Blade::directive('day', function ($expression) {
113 1
            return "<?php echo date('d', strtotime($expression))?>";
114 169
        });
115
        Blade::directive('month', function ($expression) {
116
            /*return "<?php echo date('M', strtotime($expression))?>";*/
117 1
            return "<?php echo Carbon\Carbon::parse($expression)->isoFormat('MMM')?>";
118 169
        });
119
        Blade::directive('time_am_pm', function ($expression) {
120 1
            return "<?php echo date('g.i a', strtotime($expression))?>";
121 169
        });
122 169
    }
123
124
    /**
125
     * Register the application services.
126
     */
127 169
    public function register()
128
    {
129
        // Automatically apply the package configuration
130 169
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-events-calendar');
131
132
        // Register the main class to use with the facade
133
        $this->app->singleton('laravel-events-calendar', function () {
134 32
            return new LaravelEventsCalendar;
135 169
        });
136
137
        /*
138
     * Register the service provider for the dependency.
139
     */
140 169
        $this->app->register('Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider');
141
        /*
142
         * Create aliases for the dependency.
143
         */
144 169
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
145 169
        $loader->alias('LaravelLocalization', 'Mcamara\LaravelLocalization\Facades\LaravelLocalization');
146 169
    }
147
}
148