1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\AwsSns; |
4
|
|
|
|
5
|
|
|
class SnsMessage |
6
|
|
|
{ |
7
|
|
|
const PROMOTIONAL_SMS_TYPE = 'Promotional'; |
8
|
|
|
|
9
|
|
|
const TRANSACTIONAL_SMS_TYPE = 'Transactional'; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* The body of the message. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $body = ''; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The delivery type of the message. |
20
|
|
|
* |
21
|
|
|
* @var bool |
22
|
|
|
*/ |
23
|
|
|
protected $promotional = true; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The sender identification of the message. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $sender = ''; |
31
|
|
|
|
32
|
16 |
|
public function __construct($content) |
33
|
|
|
{ |
34
|
16 |
|
if (is_string($content)) { |
35
|
5 |
|
$this->body($content); |
36
|
|
|
} |
37
|
|
|
|
38
|
16 |
|
if (is_array($content)) { |
39
|
11 |
|
foreach ($content as $property => $value) { |
40
|
5 |
|
if (method_exists($this, $property)) { |
41
|
5 |
|
$this->{$property}($value); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
16 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Creates a new instance of the message. |
49
|
|
|
* |
50
|
|
|
* @param array $data |
51
|
|
|
* @return SnsMessage |
52
|
|
|
*/ |
53
|
8 |
|
public static function create(array $data = []) |
54
|
|
|
{ |
55
|
8 |
|
return new self($data); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Sets the message body. |
60
|
|
|
* |
61
|
|
|
* @param string $content |
62
|
|
|
* @return $this |
63
|
|
|
*/ |
64
|
11 |
|
public function body(string $content) |
65
|
|
|
{ |
66
|
11 |
|
$this->body = trim($content); |
67
|
|
|
|
68
|
11 |
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get the message body. |
73
|
|
|
* |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
8 |
|
public function getBody() |
77
|
|
|
{ |
78
|
8 |
|
return $this->body; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Sets the message delivery type as promotional. |
83
|
|
|
* |
84
|
|
|
* @param bool $active |
85
|
|
|
* @return $this |
86
|
|
|
*/ |
87
|
1 |
|
public function promotional(bool $active = true) |
88
|
|
|
{ |
89
|
1 |
|
$this->promotional = $active; |
90
|
|
|
|
91
|
1 |
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Sets the message delivery type as transactional. |
96
|
|
|
* |
97
|
|
|
* @param bool $active |
98
|
|
|
* @return $this |
99
|
|
|
*/ |
100
|
3 |
|
public function transactional(bool $active = true) |
101
|
|
|
{ |
102
|
3 |
|
$this->promotional = ! $active; |
103
|
|
|
|
104
|
3 |
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get the message delivery type. |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
7 |
|
public function getDeliveryType() |
113
|
|
|
{ |
114
|
7 |
|
return $this->promotional ? self::PROMOTIONAL_SMS_TYPE : self::TRANSACTIONAL_SMS_TYPE; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Sets the message sender identification. |
119
|
|
|
* |
120
|
|
|
* @param string $sender |
121
|
|
|
* @return $this |
122
|
|
|
*/ |
123
|
3 |
|
public function sender(string $sender) |
124
|
|
|
{ |
125
|
3 |
|
$this->sender = $sender; |
126
|
|
|
|
127
|
3 |
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Get the message sender identification. |
132
|
|
|
* |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
6 |
|
public function getSender() |
136
|
|
|
{ |
137
|
6 |
|
return $this->sender; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|