1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\AllMySms; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use DateTimeInterface; |
7
|
|
|
|
8
|
|
|
class AllMySmsMessage |
9
|
|
|
{ |
10
|
|
|
const DATE_FORMAT = 'Y-m-d H:i:s'; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* The message content. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
public $content; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The sender name the message should sent from. |
21
|
|
|
* |
22
|
|
|
* @var string|null |
23
|
|
|
*/ |
24
|
|
|
public $sender; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The (optional) campaign name. |
28
|
|
|
* |
29
|
|
|
* @var string|null |
30
|
|
|
*/ |
31
|
|
|
public $campaign; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The (optional) date the message should sent at. |
35
|
|
|
* |
36
|
|
|
* @var string|null |
37
|
|
|
*/ |
38
|
|
|
public $sendAt; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The content parameters values. |
42
|
|
|
* |
43
|
|
|
* If you want to use parameters in your message you should add the following placeholder in your content: |
44
|
|
|
* "#param_x#" where x is the 1-based index of parameters array. |
45
|
|
|
* |
46
|
|
|
* <code> |
47
|
|
|
* $message->content("Hello #param_1# #param_2#") |
48
|
|
|
* ->parameters([$user->first_name, $user->last_name]); |
49
|
|
|
* </code> |
50
|
|
|
* |
51
|
|
|
* @var array|null |
52
|
|
|
*/ |
53
|
|
|
public $parameters; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Create a new message instance. |
57
|
|
|
* |
58
|
|
|
* @param string $content |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
8 |
|
public function __construct(string $content = '') |
62
|
|
|
{ |
63
|
8 |
|
$this->content = $content; |
64
|
8 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Set message content. |
68
|
|
|
* |
69
|
|
|
* @param string $content |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
1 |
|
public function content(string $content) |
73
|
|
|
{ |
74
|
1 |
|
$this->content = $content; |
75
|
|
|
|
76
|
1 |
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Set the sender name the message should sent from. |
81
|
|
|
* |
82
|
|
|
* @param string $sender |
83
|
|
|
* @return $this |
84
|
|
|
*/ |
85
|
1 |
|
public function sender(string $sender) |
86
|
|
|
{ |
87
|
1 |
|
$this->sender = $sender; |
88
|
|
|
|
89
|
1 |
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Set the campaign name. |
94
|
|
|
* |
95
|
|
|
* @param string $campaign |
96
|
|
|
* @return $this |
97
|
|
|
*/ |
98
|
1 |
|
public function campaign(string $campaign) |
99
|
|
|
{ |
100
|
1 |
|
$this->campaign = $campaign; |
101
|
|
|
|
102
|
1 |
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Set the date the message should sent at. |
107
|
|
|
* |
108
|
|
|
* @param \DateTimeInterface|string $sendAt |
109
|
|
|
* @return $this |
110
|
|
|
* @throws \Exception |
111
|
|
|
*/ |
112
|
1 |
|
public function sendAt($sendAt) |
113
|
|
|
{ |
114
|
1 |
|
if (! $sendAt instanceof DateTimeInterface) { |
115
|
|
|
$sendAt = new DateTime($sendAt); |
116
|
|
|
} |
117
|
|
|
|
118
|
1 |
|
$this->sendAt = $sendAt->format(static::DATE_FORMAT); |
119
|
|
|
|
120
|
1 |
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Set the message parameters. |
125
|
|
|
* |
126
|
|
|
* @param array $parameters |
127
|
|
|
* @return $this |
128
|
|
|
*/ |
129
|
1 |
|
public function parameters(array $parameters) |
130
|
|
|
{ |
131
|
1 |
|
$this->parameters = $parameters; |
132
|
|
|
|
133
|
1 |
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Get array representation of the message. |
138
|
|
|
* |
139
|
|
|
* @return array |
140
|
|
|
*/ |
141
|
8 |
|
public function toArray(): array |
142
|
|
|
{ |
143
|
|
|
return [ |
144
|
8 |
|
'message' => $this->content, |
145
|
8 |
|
'sender' => $this->sender, |
146
|
8 |
|
'campaign' => $this->campaign, |
147
|
8 |
|
'date' => $this->sendAt, |
148
|
8 |
|
'parameters' => $this->parameters, |
149
|
|
|
]; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|