|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Valkyrja Framework package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Melech Mizrachi <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Valkyrja\Sms\Provider; |
|
15
|
|
|
|
|
16
|
|
|
use Valkyrja\Application\Env; |
|
|
|
|
|
|
17
|
|
|
use Valkyrja\Container\Contract\Container; |
|
18
|
|
|
use Valkyrja\Container\Support\Provider; |
|
19
|
|
|
use Valkyrja\Log\Contract\Logger; |
|
20
|
|
|
use Valkyrja\Sms\Contract\Sms; |
|
21
|
|
|
use Valkyrja\Sms\LogSms; |
|
22
|
|
|
use Valkyrja\Sms\NullSms; |
|
23
|
|
|
use Valkyrja\Sms\VonageSms; |
|
24
|
|
|
use Vonage\Client as Vonage; |
|
25
|
|
|
use Vonage\Client\Credentials\Basic; |
|
26
|
|
|
use Vonage\Client\Credentials\CredentialsInterface as VonageCredentials; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Class ServiceProvider. |
|
30
|
|
|
* |
|
31
|
|
|
* @author Melech Mizrachi |
|
32
|
|
|
*/ |
|
33
|
|
|
final class ServiceProvider extends Provider |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* @inheritDoc |
|
37
|
|
|
*/ |
|
38
|
|
|
public static function publishers(): array |
|
39
|
|
|
{ |
|
40
|
|
|
return [ |
|
41
|
|
|
Sms::class => [self::class, 'publishSms'], |
|
42
|
|
|
VonageSms::class => [self::class, 'publishVonageSms'], |
|
43
|
|
|
Vonage::class => [self::class, 'publishVonage'], |
|
44
|
|
|
VonageCredentials::class => [self::class, 'publishVonageCredentials'], |
|
45
|
|
|
LogSms::class => [self::class, 'publishLogSms'], |
|
46
|
|
|
NullSms::class => [self::class, 'publishNullSms'], |
|
47
|
|
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @inheritDoc |
|
52
|
|
|
*/ |
|
53
|
|
|
public static function provides(): array |
|
54
|
|
|
{ |
|
55
|
|
|
return [ |
|
56
|
|
|
Sms::class, |
|
57
|
|
|
VonageSms::class, |
|
58
|
|
|
Vonage::class, |
|
59
|
|
|
VonageCredentials::class, |
|
60
|
|
|
LogSms::class, |
|
61
|
|
|
NullSms::class, |
|
62
|
|
|
]; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Publish the sms service. |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function publishSms(Container $container): void |
|
69
|
|
|
{ |
|
70
|
|
|
$container->setSingleton( |
|
71
|
|
|
Sms::class, |
|
72
|
|
|
$container->getSingleton(VonageSms::class), |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Publish the vonage sms service. |
|
78
|
|
|
*/ |
|
79
|
|
|
public static function publishVonageSms(Container $container): void |
|
80
|
|
|
{ |
|
81
|
|
|
$container->setSingleton( |
|
82
|
|
|
VonageSms::class, |
|
83
|
|
|
new VonageSms( |
|
84
|
|
|
$container->getSingleton(Vonage::class), |
|
85
|
|
|
), |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Publish the vonage service. |
|
91
|
|
|
*/ |
|
92
|
|
|
public static function publishVonage(Container $container): void |
|
93
|
|
|
{ |
|
94
|
|
|
$container->setSingleton( |
|
95
|
|
|
Vonage::class, |
|
96
|
|
|
new Vonage( |
|
97
|
|
|
credentials: $container->getSingleton(VonageCredentials::class) |
|
98
|
|
|
), |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Publish the vonage credentials service. |
|
104
|
|
|
*/ |
|
105
|
|
|
public static function publishVonageCredentials(Container $container): void |
|
106
|
|
|
{ |
|
107
|
|
|
$env = $container->getSingleton(Env::class); |
|
108
|
|
|
/** @var string $key */ |
|
109
|
|
|
$key = $env::SMS_VONAGE_KEY; |
|
110
|
|
|
/** @var string $secret */ |
|
111
|
|
|
$secret = $env::SMS_VONAGE_SECRET; |
|
112
|
|
|
|
|
113
|
|
|
$container->setSingleton( |
|
114
|
|
|
VonageCredentials::class, |
|
115
|
|
|
new Basic( |
|
116
|
|
|
key: $key, |
|
117
|
|
|
secret: $secret |
|
118
|
|
|
), |
|
119
|
|
|
); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Publish the log sms service. |
|
124
|
|
|
*/ |
|
125
|
|
|
public static function publishLogSms(Container $container): void |
|
126
|
|
|
{ |
|
127
|
|
|
$container->setSingleton( |
|
128
|
|
|
LogSms::class, |
|
129
|
|
|
new LogSms( |
|
130
|
|
|
$container->getSingleton(Logger::class), |
|
131
|
|
|
), |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Publish the null sms service. |
|
137
|
|
|
*/ |
|
138
|
|
|
public static function publishNullSms(Container $container): void |
|
139
|
|
|
{ |
|
140
|
|
|
$container->setSingleton( |
|
141
|
|
|
NullSms::class, |
|
142
|
|
|
new NullSms(), |
|
143
|
|
|
); |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths