1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Twilio; |
4
|
|
|
|
5
|
|
|
class TwilioConfig |
6
|
|
|
{ |
7
|
|
|
/** @var array */ |
8
|
|
|
private $config; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @param array $config |
12
|
|
|
*/ |
13
|
11 |
|
public function __construct(array $config) |
14
|
|
|
{ |
15
|
11 |
|
$this->config = $config; |
16
|
11 |
|
} |
17
|
|
|
|
18
|
|
|
public function usingUsernamePasswordAuth(): bool |
19
|
|
|
{ |
20
|
|
|
return $this->getUsername() !== null && $this->getPassword() !== null && $this->getAccountSid() !== null; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function usingTokenAuth(): bool |
24
|
|
|
{ |
25
|
|
|
return $this->getAuthToken() !== null && $this->getAccountSid() !== null; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getAuthToken(): ?string |
29
|
|
|
{ |
30
|
|
|
return $this->config['auth_token'] ?? null; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getUsername(): ?string |
34
|
|
|
{ |
35
|
|
|
return $this->config['username'] ?? null; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getPassword(): ?string |
39
|
|
|
{ |
40
|
|
|
return $this->config['password'] ?? null; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getAccountSid(): ?string |
44
|
|
|
{ |
45
|
|
|
return $this->config['account_sid'] ?? null; |
46
|
|
|
} |
47
|
|
|
|
48
|
3 |
|
public function getFrom(): ?string |
49
|
|
|
{ |
50
|
3 |
|
return $this->config['from'] ?? null; |
51
|
|
|
} |
52
|
|
|
|
53
|
1 |
|
public function getAlphanumericSender(): ?string |
54
|
|
|
{ |
55
|
1 |
|
return $this->config['alphanumeric_sender'] ?? null; |
56
|
|
|
} |
57
|
|
|
|
58
|
3 |
|
public function getServiceSid(): ?string |
59
|
|
|
{ |
60
|
3 |
|
return $this->config['sms_service_sid'] ?? null; |
61
|
|
|
} |
62
|
|
|
|
63
|
3 |
|
public function getDebugTo(): ?string |
64
|
|
|
{ |
65
|
3 |
|
return $this->config['debug_to'] ?? null; |
66
|
|
|
} |
67
|
|
|
|
68
|
5 |
|
public function getIgnoredErrorCodes(): array |
69
|
|
|
{ |
70
|
5 |
|
return $this->config['ignored_error_codes'] ?? []; |
71
|
|
|
} |
72
|
|
|
|
73
|
5 |
|
public function isIgnoredErrorCode(int $code): bool |
74
|
|
|
{ |
75
|
5 |
|
if (in_array('*', $this->getIgnoredErrorCodes(), true)) { |
76
|
1 |
|
return true; |
77
|
|
|
} |
78
|
|
|
|
79
|
4 |
|
return in_array($code, $this->getIgnoredErrorCodes(), true); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|