Completed
Push — master ( 9e8068...98b1ac )
by Abdelrahman
03:05 queued 01:48
created

StatisticsServiceProvider::register()   C

Complexity

Conditions 9
Paths 256

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 6.5222
c 0
b 0
f 0
cc 9
nc 256
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Statistics\Providers;
6
7
use Illuminate\Routing\Router;
8
use Rinvex\Statistics\Models\Path;
9
use Rinvex\Statistics\Models\Agent;
10
use Rinvex\Statistics\Models\Datum;
11
use Rinvex\Statistics\Models\Geoip;
12
use Rinvex\Statistics\Models\Route;
13
use Rinvex\Statistics\Models\Device;
14
use Rinvex\Statistics\Models\Request;
15
use Rinvex\Statistics\Models\Platform;
16
use Illuminate\Support\ServiceProvider;
17
use Rinvex\Support\Traits\ConsoleTools;
18
use Rinvex\Statistics\Console\Commands\MigrateCommand;
19
use Rinvex\Statistics\Console\Commands\PublishCommand;
20
use Rinvex\Statistics\Http\Middleware\TrackStatistics;
21
use Rinvex\Statistics\Console\Commands\RollbackCommand;
22
23
class StatisticsServiceProvider extends ServiceProvider
24
{
25
    use ConsoleTools;
26
27
    /**
28
     * The commands to be registered.
29
     *
30
     * @var array
31
     */
32
    protected $commands = [
33
        MigrateCommand::class => 'command.rinvex.statistics.migrate',
34
        PublishCommand::class => 'command.rinvex.statistics.publish',
35
        RollbackCommand::class => 'command.rinvex.statistics.rollback',
36
    ];
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function register()
42
    {
43
        // Merge config
44
        $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.statistics');
45
46
        // Bind eloquent models to IoC container
47
        $this->app->singleton('rinvex.statistics.datum', $datumModel = $this->app['config']['rinvex.statistics.models.datum']);
48
        $datumModel === Datum::class || $this->app->alias('rinvex.statistics.datum', Datum::class);
49
50
        $this->app->singleton('rinvex.statistics.request', $requestModel = $this->app['config']['rinvex.statistics.models.request']);
51
        $requestModel === Request::class || $this->app->alias('rinvex.statistics.request', Request::class);
52
53
        $this->app->singleton('rinvex.statistics.agent', $agentModel = $this->app['config']['rinvex.statistics.models.agent']);
54
        $agentModel === Agent::class || $this->app->alias('rinvex.statistics.agent', Agent::class);
55
56
        $this->app->singleton('rinvex.statistics.geoip', $geoipModel = $this->app['config']['rinvex.statistics.models.geoip']);
57
        $geoipModel === Geoip::class || $this->app->alias('rinvex.statistics.geoip', Geoip::class);
58
59
        $this->app->singleton('rinvex.statistics.route', $routeModel = $this->app['config']['rinvex.statistics.models.route']);
60
        $routeModel === Route::class || $this->app->alias('rinvex.statistics.route', Route::class);
61
62
        $this->app->singleton('rinvex.statistics.device', $deviceModel = $this->app['config']['rinvex.statistics.models.device']);
63
        $deviceModel === Device::class || $this->app->alias('rinvex.statistics.device', Device::class);
64
65
        $this->app->singleton('rinvex.statistics.platform', $platformModel = $this->app['config']['rinvex.statistics.models.platform']);
66
        $platformModel === Platform::class || $this->app->alias('rinvex.statistics.platform', Platform::class);
67
68
        $this->app->singleton('rinvex.statistics.path', $pathModel = $this->app['config']['rinvex.statistics.models.path']);
69
        $pathModel === Path::class || $this->app->alias('rinvex.statistics.path', Path::class);
70
71
        // Register console commands
72
        $this->registerCommands();
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function boot(Router $router)
79
    {
80
        // Publish Resources
81
        $this->publishesConfig('rinvex/laravel-statistics');
82
        $this->publishesMigrations('rinvex/laravel-statistics');
83
        ! $this->autoloadMigrations('rinvex/laravel-statistics') || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
84
85
        // Push middleware to web group
86
        $router->pushMiddlewareToGroup('web', TrackStatistics::class);
87
    }
88
}
89