1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Twilio; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Foundation\Application; |
6
|
|
|
use Illuminate\Contracts\Support\DeferrableProvider; |
7
|
|
|
use Illuminate\Support\ServiceProvider; |
8
|
|
|
use NotificationChannels\Twilio\Exceptions\InvalidConfigException; |
9
|
|
|
use Twilio\Rest\Client as TwilioService; |
10
|
|
|
|
11
|
|
|
class TwilioProvider extends ServiceProvider implements DeferrableProvider |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Bootstrap the application services. |
15
|
|
|
*/ |
16
|
2 |
|
public function boot() |
17
|
|
|
{ |
18
|
2 |
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Register the application services. |
22
|
|
|
*/ |
23
|
|
|
public function register() |
24
|
|
|
{ |
25
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/twilio-notification-channel.php', ''); |
26
|
|
|
|
27
|
|
|
$this->publishes([ |
28
|
|
|
__DIR__.'/../config/twilio-notification-channel.php' => config_path('twilio-notification-channel.php'), |
29
|
|
|
]); |
30
|
|
|
|
31
|
|
|
$this->app->bind(TwilioConfig::class, function () { |
32
|
|
|
return new TwilioConfig($this->app['config']['twilio-notification-channel']); |
33
|
|
|
}); |
34
|
|
|
|
35
|
|
|
$this->app->singleton(TwilioChannel::class, function (Application $app) { |
|
|
|
|
36
|
|
|
return new Twilio( |
37
|
|
|
$this->app->make(TwilioService::class), |
38
|
|
|
$this->app->make(TwilioConfig::class) |
39
|
|
|
); |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
$this->app->singleton(TwilioService::class, function (Application $app) { |
43
|
|
|
/** @var TwilioConfig $config */ |
44
|
|
|
$config = $app->make(TwilioConfig::class); |
45
|
|
|
|
46
|
|
|
if ($config->usingUsernamePasswordAuth()) { |
47
|
|
|
return new TwilioService($config->getUsername(), $config->getPassword(), $config->getAccountSid()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if ($config->usingTokenAuth()) { |
51
|
|
|
return new TwilioService($config->getAccountSid(), $config->getAuthToken()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
throw InvalidConfigException::missingConfig(); |
55
|
|
|
}); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get the services provided by the provider. |
60
|
|
|
* |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function provides(): array |
64
|
|
|
{ |
65
|
|
|
return [ |
66
|
|
|
TwilioConfig::class, |
67
|
|
|
TwilioService::class, |
68
|
|
|
TwilioChannel::class, |
69
|
|
|
]; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.