SignereServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Sausin\Signere;
4
5
use Illuminate\Support\Facades\Route;
6
use Illuminate\Support\ServiceProvider;
7
use Illuminate\Contracts\Events\Dispatcher;
8
9
class SignereServiceProvider extends ServiceProvider
10
{
11
    use EventMap;
12
13
    /**
14
     * Bootstrap the application services.
15
     *
16
     * @return void
17
     */
18 66
    public function boot()
19
    {
20
        // $this->registerEvents();
21 66
        $this->registerRoutes();
22 66
        $this->defineAssetPublishing();
23 66
    }
24
25
    /**
26
     * Register the Signere job events.
27
     *
28
     * @return void
29
     */
30
    protected function registerEvents()
31
    {
32
        $events = $this->app->make(Dispatcher::class);
33
34
        foreach ($this->events as $event => $listeners) {
35
            foreach ($listeners as $listener) {
36
                $events->listen($event, $listener);
37
            }
38
        }
39
    }
40
41
    /**
42
     * Register the Signere routes.
43
     *
44
     * @return void
45
     */
46 66
    protected function registerRoutes()
47
    {
48 66
        Route::group([
49 66
            'prefix' => 'signere',
50
            'namespace' => 'Sausin\Signere\Http\Controllers',
51
            'middleware' => 'api',
52 66
        ], function () {
53 66
            $this->loadRoutesFrom(__DIR__.'/../routes/api.php');
54 66
        });
55 66
    }
56
57
    /**
58
     * Define the asset publishing configuration.
59
     *
60
     * @return void
61
     */
62 66
    public function defineAssetPublishing()
63
    {
64 66
        $this->publishes([
65 66
            SIGNERE_PATH.'/public' => public_path('vendor/signere'),
66 66
        ], 'signere-assets');
67 66
    }
68
69
    /**
70
     * Register any application services.
71
     *
72
     * @return void
73
     */
74 66
    public function register()
75
    {
76 66
        if (! defined('SIGNERE_PATH')) {
77 1
            define('SIGNERE_PATH', realpath(__DIR__.'/../'));
78
        }
79
80 66
        $this->configure();
81 66
        $this->registerCommands();
82 66
        $this->registerBindings();
83 66
        $this->offerPublishing();
84 66
    }
85
86
    /**
87
     * Setup the configuration for Signere.
88
     *
89
     * @return void
90
     */
91 66
    protected function configure()
92
    {
93 66
        $this->mergeConfigFrom(
94 66
            __DIR__.'/../config/signere.php',
95 66
            'signere'
96
        );
97 66
    }
98
99
    /**
100
     * Registers the commands available with this package.
101
     *
102
     * @return void
103
     */
104 66
    protected function registerCommands()
105
    {
106 66
        if ($this->app->runningInConsole()) {
107
            // register the console command
108 66
            $this->commands([Console\RenewCommand::class]);
109
        }
110 66
    }
111
112
    /**
113
     * Register the bindings.
114
     *
115
     * @return void
116
     */
117
    protected function registerBindings()
118
    {
119 66
        $this->app->bind('signere-headers', function () {
120 1
            return new Headers(config());
121 66
        });
122 66
        $this->app->alias('signere-headers', Facades\SignereHeaders::class);
123
124
        $classes = [
125 66
            'ApiKey',
126
            'Document',
127
            'DocumentConvert',
128
            'DocumentFile',
129
            'DocumentJob',
130
            'DocumentProvider',
131
            'Events',
132
            'ExternalLogin',
133
            'ExternalSign',
134
            'Form',
135
            'Invoice',
136
            'Message',
137
            'Receiver',
138
            'RequestId',
139
            'Statistics',
140
            'Status',
141
        ];
142
143
        // get the environment of the application
144 66
        $env = is_null(config('signere.mode')) ? $this->app->environment() : config('signere.mode');
145
146 66
        foreach ($classes as $class) {
147 66
            $this->app->when('Sausin\Signere\\'.$class)
148 66
                        ->needs('$environment')
149 66
                        ->give($env);
150
        }
151 66
    }
152
153
    /**
154
     * Setup the resource publishing groups for Signere.
155
     *
156
     * @return void
157
     */
158 66
    protected function offerPublishing()
159
    {
160 66
        if ($this->app->runningInConsole()) {
161 66
            $this->publishes([
162 66
                __DIR__.'/../config/signere.php' => config_path('signere.php'),
163 66
            ], 'signere-config');
164
        }
165 66
    }
166
}
167