Completed
Pull Request — master (#2)
by Simon
03:13
created

SipgateServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 19
nc 1
nop 0
dl 0
loc 28
ccs 0
cts 21
cp 0
crap 2
rs 9.6333
c 0
b 0
f 0
1
<?php
2
3
namespace NotificationChannels\Sipgate;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Contracts\Foundation\Application;
7
use Illuminate\Notifications\ChannelManager;
8
use Illuminate\Support\ServiceProvider;
9
10
class SipgateServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap the application services.
14
     */
15
    public function boot()
16
    {
17
        $this->app->afterResolving(ChannelManager::class, function (ChannelManager $channels) {
18
            $channels->extend('sipgate', function ($app) {
19
                /* @var Application $app */
20
                return $app->make(SipgateChannel::class);
21
            });
22
        });
23
24
        $this->app->when(SipgateChannel::class)
25
            ->needs('$smsId')
26
            ->give($this->app['config']['services.sipgate.smsId']);
27
28
        $this->app->when(SipgateChannel::class)
29
            ->needs('$channelEnabled')
30
            ->give($this->app['config']['services.sipgate.enabled']);
31
32
        $this->app->bind(SipgateClient::class, function () {
33
            return new SipgateClient(
34
                new Client([
35
                    'base_uri' => 'https://api.sipgate.com/v2/',
36
                    'auth' => [
37
                        $this->app['config']['services.sipgate.username'],
38
                        $this->app['config']['services.sipgate.password'],
39
                    ],
40
                    'headers' => [
41
                        'Accept' => 'application/json',
42
                        'Content-Type' => 'application/json',
43
                    ],
44
                ])
45
            );
46
        });
47
    }
48
}
49