|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Author: Hilmi Erdem KEREN |
|
4
|
|
|
* Date: 17/11/2016. |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace NotificationChannels\JetSMS; |
|
8
|
|
|
|
|
9
|
|
|
use Carbon\Carbon; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class JetSMSMessage. |
|
13
|
|
|
*/ |
|
14
|
|
|
final class JetSMSMessage implements JetSMSMessageInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* The message content. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
private $content; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The number to be notified. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
private $number; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The message sender. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
private $originator; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The date message will be sent. |
|
39
|
|
|
* |
|
40
|
|
|
* @var Carbon|null |
|
41
|
|
|
*/ |
|
42
|
|
|
private $sendDate = null; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* JetSMSMessage constructor. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $content |
|
48
|
|
|
* @param string $number |
|
49
|
|
|
* @param string|null $originator |
|
50
|
|
|
* @param Carbon|string|null $sendDate |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct($content, $number, $originator = null, $sendDate = null) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->content = $content; |
|
55
|
|
|
$this->number = $number; |
|
56
|
|
|
|
|
57
|
|
|
if (! is_null($originator)) { |
|
58
|
|
|
$this->originator = $originator; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if (! is_null($sendDate)) { |
|
62
|
|
|
$this->sendDate = $sendDate instanceof Carbon ? $sendDate : Carbon::createFromFormat($this->dateFormat(), $sendDate); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get the message properties as array. |
|
68
|
|
|
* |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
|
public function toArray() |
|
72
|
|
|
{ |
|
73
|
|
|
return array_filter([ |
|
74
|
|
|
'Msisdns' => $this->number(), |
|
75
|
|
|
'Messages' => $this->content(), |
|
76
|
|
|
'SendDate' => $this->sendDate() ? $this->sendDate()->format($this->dateFormat()) : null, |
|
77
|
|
|
'TransmissionID' => $this->originator(), |
|
78
|
|
|
]); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Convert the sms message to sms parameters. |
|
83
|
|
|
* |
|
84
|
|
|
* @return array |
|
85
|
|
|
*/ |
|
86
|
|
|
public function toRequestParams() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->toArray(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get the short message. |
|
93
|
|
|
* |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
public function content() |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->content; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get the to number. |
|
103
|
|
|
* |
|
104
|
|
|
* @return string |
|
105
|
|
|
*/ |
|
106
|
|
|
public function number() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->number; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Get the outbox name of the message. |
|
113
|
|
|
* |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
public function originator() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->originator; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Get the send date of the short message. |
|
123
|
|
|
* |
|
124
|
|
|
* @return Carbon|null |
|
125
|
|
|
*/ |
|
126
|
|
|
public function sendDate() |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->sendDate; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Property getter. |
|
133
|
|
|
* |
|
134
|
|
|
* @param string $name |
|
135
|
|
|
* @return mixed |
|
136
|
|
|
*/ |
|
137
|
|
|
public function __get($name) |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->$name(); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Get the api date format. |
|
144
|
|
|
* |
|
145
|
|
|
* @return string |
|
146
|
|
|
*/ |
|
147
|
|
|
private function dateFormat() |
|
148
|
|
|
{ |
|
149
|
|
|
return 'Y-m-d H:i:s'; |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|