Completed
Push — master ( 722808...ad4a08 )
by Saurabh
08:30
created

SignereServiceProvider   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 144
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 88.24%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 144
ccs 45
cts 51
cp 0.8824
rs 10
c 1
b 0
f 0
wmc 14
lcom 1
cbo 6

8 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A registerEvents() 0 10 3
A registerRoutes() 0 10 1
A defineAssetPublishing() 0 6 1
A register() 0 10 2
A configure() 0 7 1
B registerBindings() 0 35 3
A offerPublishing() 0 8 2
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 61
    public function boot()
19
    {
20
        // $this->registerEvents();
21 61
        $this->registerRoutes();
22 61
        $this->defineAssetPublishing();
23 61
    }
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 61
    protected function registerRoutes()
47
    {
48 61
        Route::group([
49 61
            'prefix' => 'signere',
50
            'namespace' => 'Sausin\Signere\Http\Controllers',
51
            'middleware' => 'web',
52 61
        ], function () {
53 61
            $this->loadRoutesFrom(__DIR__.'/../routes/api.php');
54 61
        });
55 61
    }
56
57
    /**
58
     * Define the asset publishing configuration.
59
     *
60
     * @return void
61
     */
62 61
    public function defineAssetPublishing()
63
    {
64 61
        $this->publishes([
65 61
            SIGNERE_PATH.'/public' => public_path('vendor/signere'),
66 61
        ], 'signere-assets');
67 61
    }
68
69
    /**
70
     * Register any application services.
71
     *
72
     * @return void
73
     */
74 61
    public function register()
75
    {
76 61
        if (! defined('SIGNERE_PATH')) {
77 1
            define('SIGNERE_PATH', realpath(__DIR__.'/../'));
78
        }
79
80 61
        $this->registerBindings();
81 61
        $this->configure();
82 61
        $this->offerPublishing();
83 61
    }
84
85
    /**
86
     * Setup the configuration for Signere.
87
     *
88
     * @return void
89
     */
90 61
    protected function configure()
91
    {
92 61
        $this->mergeConfigFrom(
93 61
            __DIR__.'/../config/signere.php',
94 61
            'signere'
95
        );
96 61
    }
97
98
    /**
99
     * Register the bindings.
100
     *
101
     * @return void
102
     */
103
    protected function registerBindings()
104
    {
105 61
        $this->app->bind('signere-headers', function () {
106 1
            return new Headers(config());
107 61
        });
108 61
        $this->app->alias('signere-headers', Facades\SignereHeaders::class);
109
110
        $classes = [
111 61
            'ApiKey',
112
            'Document',
113
            'DocumentConvert',
114
            'DocumentFile',
115
            'DocumentJob',
116
            'DocumentProvider',
117
            'Events',
118
            'ExternalLogin',
119
            'ExternalSign',
120
            'Form',
121
            'Invoice',
122
            'Message',
123
            'Receiver',
124
            'RequestId',
125
            'Statistics',
126
            'Status',
127
        ];
128
129
        // get the environment of the application
130 61
        $env = is_null(config('signere.mode')) ? $this->app->environment() : config('signere.mode');
131
132 61
        foreach ($classes as $class) {
133 61
            $this->app->when('Sausin\Signere\\'.$class)
134 61
                        ->needs('$environment')
135 61
                        ->give($env);
136
        }
137 61
    }
138
139
    /**
140
     * Setup the resource publishing groups for Signere.
141
     *
142
     * @return void
143
     */
144 61
    protected function offerPublishing()
145
    {
146 61
        if ($this->app->runningInConsole()) {
147 61
            $this->publishes([
148 61
                __DIR__.'/../config/signere.php' => config_path('signere.php'),
149 61
            ], 'signere-config');
150
        }
151 61
    }
152
}
153