Completed
Pull Request — master (#12)
by Saurabh
05:34
created

SignereServiceProvider::defineAssetPublishing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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