1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Zing\LaravelSms; |
6
|
|
|
|
7
|
|
|
use Illuminate\Contracts\Container\Container; |
8
|
|
|
use Illuminate\Foundation\Application as Laravel; |
9
|
|
|
use Illuminate\Notifications\ChannelManager; |
10
|
|
|
use Illuminate\Support\Facades\Notification; |
11
|
|
|
use Illuminate\Support\ServiceProvider; |
12
|
|
|
use Laravel\Lumen\Application as Lumen; |
13
|
|
|
use Zing\LaravelSms\Channels\SmsChannel; |
14
|
|
|
use Zing\LaravelSms\Commands\SmsSwitchConnectionCommand; |
15
|
|
|
use Zing\LaravelSms\Facades\Sms; |
16
|
|
|
|
17
|
|
|
class SmsServiceProvider extends ServiceProvider |
18
|
|
|
{ |
19
|
53 |
|
public function boot(): void |
20
|
|
|
{ |
21
|
53 |
|
if ($this->app->runningInConsole() && $this->app instanceof Laravel) { |
22
|
48 |
|
$this->publishes( |
23
|
|
|
[ |
24
|
48 |
|
$this->getConfigPath() => config_path('sms.php'), |
25
|
|
|
], |
26
|
48 |
|
'config' |
27
|
|
|
); |
28
|
|
|
} |
29
|
53 |
|
} |
30
|
|
|
|
31
|
53 |
|
public function register(): void |
32
|
|
|
{ |
33
|
53 |
|
$this->registerConfig(); |
34
|
53 |
|
Notification::resolved( |
35
|
|
|
function (ChannelManager $service): void { |
36
|
9 |
|
$service->extend( |
37
|
9 |
|
'sms', |
38
|
|
|
function (Container $app) { |
39
|
2 |
|
return $app->make(SmsChannel::class); |
40
|
9 |
|
} |
41
|
|
|
); |
42
|
53 |
|
} |
43
|
|
|
); |
44
|
53 |
|
$this->app->singleton( |
45
|
53 |
|
'sms', |
46
|
|
|
function (Container $app) { |
47
|
18 |
|
return $app->make(SmsManager::class); |
48
|
53 |
|
} |
49
|
|
|
); |
50
|
53 |
|
$this->app->alias('sms', Sms::class); |
51
|
53 |
|
$this->registerCommands(); |
52
|
53 |
|
} |
53
|
|
|
|
54
|
53 |
|
protected function getConfigPath(): string |
55
|
|
|
{ |
56
|
53 |
|
return __DIR__ . '/../config/sms.php'; |
57
|
|
|
} |
58
|
|
|
|
59
|
53 |
|
protected function registerConfig(): void |
60
|
|
|
{ |
61
|
53 |
|
if ($this->app instanceof Lumen) { |
62
|
5 |
|
$this->app->configure('sms'); |
63
|
|
|
} |
64
|
|
|
|
65
|
53 |
|
$this->mergeConfigFrom($this->getConfigPath(), 'sms'); |
66
|
53 |
|
} |
67
|
|
|
|
68
|
53 |
|
protected function registerCommands(): void |
69
|
|
|
{ |
70
|
53 |
|
$this->app->singleton('command.sms.gateway', SmsSwitchConnectionCommand::class); |
71
|
53 |
|
$this->commands( |
72
|
|
|
[ |
73
|
53 |
|
'command.sms.gateway', |
74
|
|
|
] |
75
|
|
|
); |
76
|
53 |
|
} |
77
|
|
|
} |
78
|
|
|
|