AutoIncrementServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Sausin\DBSetAutoIncrement;
4
5
use Illuminate\Contracts\Events\Dispatcher;
6
use Illuminate\Support\ServiceProvider;
7
8
class AutoIncrementServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     *
13
     * @return void
14
     */
15
    public function boot()
16
    {
17
        $this->registerListener();
18
        $this->registerCommand();
19
    }
20
21
    /**
22
     * Register the listener.
23
     *
24
     * @return void
25
     */
26
    protected function registerListener()
27
    {
28
        $events = $this->app->make(Dispatcher::class);
29
30
        $events->listen(
31
            \Illuminate\Database\Events\MigrationsEnded::class,
32
            Listeners\SetAutoIncrement::class
33
        );
34
    }
35
36
    protected function registerCommand()
37
    {
38
        if ($this->app->runningInConsole()) {
39
            $this->commands([
40
                Commands\SetAutoIncrementCommand::class,
41
            ]);
42
        }
43
    }
44
45
    /**
46
     * Register any application services.
47
     *
48
     * @return void
49
     */
50
    public function register()
51
    {
52
        if (! defined('DB_AUTO_INCREMENT_PATH')) {
53
            define('DB_AUTO_INCREMENT_PATH', realpath(__DIR__.'/../'));
54
        }
55
56
        $this->configure();
57
        $this->offerPublishing();
58
    }
59
60
    /**
61
     * Setup the configuration for AutoIncrement.
62
     *
63
     * @return void
64
     */
65
    protected function configure()
66
    {
67
        $this->mergeConfigFrom(
68
            __DIR__.'/../config/auto-increment.php',
69
            'auto-increment'
70
        );
71
    }
72
73
    /**
74
     * Setup the resource publishing groups for AutoIncrement.
75
     *
76
     * @return void
77
     */
78
    protected function offerPublishing()
79
    {
80
        if ($this->app->runningInConsole()) {
81
            $this->publishes([
82
                __DIR__.'/../config/auto-increment.php' => config_path('auto-increment.php'),
83
            ], 'auto-increment-config');
84
        }
85
    }
86
}
87