Completed
Push — develop ( 3681a9...24b5cc )
by Abdelrahman
12:34
created

StatisticsServiceProvider::boot()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 25
rs 8.8571
c 2
b 0
f 0
cc 3
eloc 16
nc 4
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Statistics\Providers;
6
7
use Illuminate\Routing\Router;
8
use Illuminate\Support\ServiceProvider;
9
use Cortex\Statistics\Console\Commands\SeedCommand;
10
use Illuminate\Database\Eloquent\Relations\Relation;
11
use Cortex\Statistics\Console\Commands\InstallCommand;
12
use Cortex\Statistics\Console\Commands\MigrateCommand;
13
use Cortex\Statistics\Console\Commands\PublishCommand;
14
use Cortex\Statistics\Console\Commands\RollbackCommand;
15
16
class StatisticsServiceProvider extends ServiceProvider
17
{
18
    /**
19
     * The commands to be registered.
20
     *
21
     * @var array
22
     */
23
    protected $commands = [
24
        SeedCommand::class => 'command.cortex.statistics.seed',
25
        InstallCommand::class => 'command.cortex.statistics.install',
26
        MigrateCommand::class => 'command.cortex.statistics.migrate',
27
        PublishCommand::class => 'command.cortex.statistics.publish',
28
        RollbackCommand::class => 'command.cortex.statistics.rollback',
29
    ];
30
31
    /**
32
     * Register any application services.
33
     *
34
     * This service provider is a great spot to register your various container
35
     * bindings with the application. As you can see, we are registering our
36
     * "Registrar" implementation here. You can add your own bindings too!
37
     *
38
     * @return void
39
     */
40
    public function register(): void
41
    {
42
        // Register console commands
43
        ! $this->app->runningInConsole() || $this->registerCommands();
44
    }
45
46
    /**
47
     * Bootstrap any application services.
48
     *
49
     * @return void
50
     */
51
    public function boot(Router $router): void
52
    {
53
        // Map relations
54
        Relation::morphMap([
55
            'path' => config('rinvex.statistics.models.path'),
56
            'agent' => config('rinvex.statistics.models.agent'),
57
            'geoip' => config('rinvex.statistics.models.geoip'),
58
            'route' => config('rinvex.statistics.models.route'),
59
            'device' => config('rinvex.statistics.models.device'),
60
            'request' => config('rinvex.statistics.models.request'),
61
            'platform' => config('rinvex.statistics.models.platform'),
62
        ]);
63
64
        // Load resources
65
        require __DIR__.'/../../routes/breadcrumbs.php';
66
        $this->loadRoutesFrom(__DIR__.'/../../routes/web.php');
67
        $this->loadTranslationsFrom(__DIR__.'/../../resources/lang', 'cortex/statistics');
68
        ! $this->app->runningInConsole() || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
69
        $this->app->afterResolving('blade.compiler', function () {
70
            require __DIR__.'/../../routes/menus.php';
71
        });
72
73
        // Publish Resources
74
        ! $this->app->runningInConsole() || $this->publishResources();
75
    }
76
77
    /**
78
     * Publish resources.
79
     *
80
     * @return void
81
     */
82
    protected function publishResources(): void
83
    {
84
        $this->publishes([realpath(__DIR__.'/../../database/migrations') => database_path('migrations')], 'cortex-statistics-migrations');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
85
        $this->publishes([realpath(__DIR__.'/../../resources/lang') => resource_path('lang/vendor/cortex/statistics')], 'cortex-statistics-lang');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 146 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
86
    }
87
88
    /**
89
     * Register console commands.
90
     *
91
     * @return void
92
     */
93
    protected function registerCommands(): void
94
    {
95
        // Register artisan commands
96
        foreach ($this->commands as $key => $value) {
97
            $this->app->singleton($value, $key);
98
        }
99
100
        $this->commands(array_values($this->commands));
101
    }
102
}
103