|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\Twilio; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Arr; |
|
6
|
|
|
use Illuminate\Support\ServiceProvider; |
|
7
|
|
|
use Twilio\Rest\Client as TwilioService; |
|
8
|
|
|
use Illuminate\Contracts\Support\DeferrableProvider; |
|
9
|
|
|
|
|
10
|
|
|
class TwilioProvider extends ServiceProvider implements DeferrableProvider |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Bootstrap the application services. |
|
14
|
|
|
*/ |
|
15
|
2 |
|
public function boot() |
|
16
|
|
|
{ |
|
17
|
2 |
|
$this->app->when(TwilioChannel::class) |
|
18
|
2 |
|
->needs(Twilio::class) |
|
19
|
|
|
->give(function () { |
|
20
|
2 |
|
return new Twilio( |
|
21
|
2 |
|
$this->app->make(TwilioService::class), |
|
22
|
2 |
|
$this->app->make(TwilioConfig::class) |
|
23
|
|
|
); |
|
24
|
2 |
|
}); |
|
25
|
|
|
|
|
26
|
|
|
$this->app->bind(TwilioService::class, function () { |
|
27
|
2 |
|
$config = $this->app['config']['services.twilio']; |
|
28
|
2 |
|
$account_sid = Arr::get($config, 'account_sid'); |
|
29
|
2 |
|
$username = Arr::get($config, 'username'); |
|
30
|
2 |
|
if (! empty($username)) { |
|
31
|
1 |
|
$password = Arr::get($config, 'password'); |
|
32
|
|
|
|
|
33
|
1 |
|
return new TwilioService($username, $password, $account_sid); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
1 |
|
$auth_token = Arr::get($config, 'auth_token'); |
|
37
|
|
|
|
|
38
|
1 |
|
return new TwilioService($account_sid, $auth_token); |
|
39
|
2 |
|
}); |
|
40
|
2 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Register the application services. |
|
44
|
|
|
*/ |
|
45
|
|
|
public function register() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->app->bind(TwilioConfig::class, function () { |
|
48
|
|
|
return new TwilioConfig($this->app['config']['services.twilio']); |
|
49
|
|
|
}); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get the services provided by the provider. |
|
54
|
|
|
* |
|
55
|
|
|
* @return array |
|
56
|
|
|
*/ |
|
57
|
|
|
public function provides() |
|
58
|
|
|
{ |
|
59
|
|
|
return [ |
|
60
|
|
|
TwilioConfig::class, |
|
61
|
|
|
TwilioService::class, |
|
62
|
|
|
TwilioChannel::class, |
|
63
|
|
|
]; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|