|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\Cmsms; |
|
4
|
|
|
|
|
5
|
|
|
use NotificationChannels\Cmsms\Exceptions\InvalidMessage; |
|
6
|
|
|
|
|
7
|
|
|
class CmsmsMessage |
|
8
|
|
|
{ |
|
9
|
|
|
/** @var string */ |
|
10
|
|
|
protected $body; |
|
11
|
|
|
|
|
12
|
|
|
/** @var string */ |
|
13
|
|
|
protected $originator; |
|
14
|
|
|
|
|
15
|
|
|
/** @var string */ |
|
16
|
|
|
protected $reference; |
|
17
|
|
|
|
|
18
|
|
|
/** @var int */ |
|
19
|
|
|
protected $tariff = 0; |
|
20
|
|
|
|
|
21
|
|
|
/** @var int */ |
|
22
|
|
|
protected $minimumNumberOfMessageParts; |
|
23
|
|
|
|
|
24
|
|
|
/** @var int */ |
|
25
|
|
|
protected $maximumNumberOfMessageParts; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param string $body |
|
29
|
|
|
*/ |
|
30
|
25 |
|
public function __construct($body = '') |
|
31
|
|
|
{ |
|
32
|
25 |
|
$this->body($body); |
|
33
|
25 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param string $body |
|
37
|
|
|
* @return $this |
|
38
|
|
|
*/ |
|
39
|
25 |
|
public function body($body) |
|
40
|
|
|
{ |
|
41
|
25 |
|
$this->body = trim($body); |
|
42
|
|
|
|
|
43
|
25 |
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param string|int $originator |
|
48
|
|
|
* @return $this |
|
49
|
|
|
* @throws InvalidMessage |
|
50
|
|
|
*/ |
|
51
|
9 |
|
public function originator($originator) |
|
52
|
|
|
{ |
|
53
|
9 |
|
if (empty($originator) || strlen($originator) > 11) { |
|
54
|
2 |
|
throw InvalidMessage::invalidOriginator($originator); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
7 |
|
$this->originator = (string) $originator; |
|
58
|
|
|
|
|
59
|
7 |
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param string $reference |
|
64
|
|
|
* @return $this |
|
65
|
|
|
* @throws InvalidMessage |
|
66
|
|
|
*/ |
|
67
|
4 |
|
public function reference($reference) |
|
68
|
|
|
{ |
|
69
|
4 |
|
if (empty($reference) || strlen($reference) > 32 || ! ctype_alnum($reference)) { |
|
70
|
3 |
|
throw InvalidMessage::invalidReference($reference); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
$this->reference = $reference; |
|
74
|
|
|
|
|
75
|
1 |
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param int $tariff Tariff in eurocent |
|
80
|
|
|
* @return $this |
|
81
|
|
|
* @throws InvalidMessage |
|
82
|
|
|
*/ |
|
83
|
4 |
|
public function tariff($tariff) |
|
84
|
|
|
{ |
|
85
|
4 |
|
if (empty($tariff) || ! is_int($tariff)) { |
|
86
|
2 |
|
throw InvalidMessage::invalidTariff($tariff); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
2 |
|
$this->tariff = $tariff; |
|
90
|
|
|
|
|
91
|
2 |
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return int |
|
96
|
|
|
*/ |
|
97
|
5 |
|
public function getTariff() |
|
98
|
|
|
{ |
|
99
|
5 |
|
return $this->tariff; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param int $minimum |
|
104
|
|
|
* @param int $maximum |
|
105
|
|
|
* @return $this |
|
106
|
|
|
* @throws InvalidMessage |
|
107
|
|
|
*/ |
|
108
|
4 |
|
public function multipart($minimum, $maximum) |
|
109
|
|
|
{ |
|
110
|
4 |
|
if (! is_int($minimum) || ! is_int($maximum) || $maximum > 8 || $minimum >= $maximum) { |
|
111
|
3 |
|
throw InvalidMessage::invalidMultipart($minimum, $maximum); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
1 |
|
$this->minimumNumberOfMessageParts = $minimum; |
|
115
|
1 |
|
$this->maximumNumberOfMessageParts = $maximum; |
|
116
|
|
|
|
|
117
|
1 |
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return array |
|
122
|
|
|
*/ |
|
123
|
11 |
|
public function toXmlArray() |
|
124
|
|
|
{ |
|
125
|
11 |
|
return array_filter([ |
|
126
|
11 |
|
'BODY' => $this->body, |
|
127
|
11 |
|
'FROM' => $this->originator, |
|
128
|
11 |
|
'REFERENCE' => $this->reference, |
|
129
|
11 |
|
'MINIMUMNUMBEROFMESSAGEPARTS' => $this->minimumNumberOfMessageParts, |
|
130
|
11 |
|
'MAXIMUMNUMBEROFMESSAGEPARTS' => $this->maximumNumberOfMessageParts, |
|
131
|
11 |
|
]); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @param string $body |
|
136
|
|
|
* @return static |
|
137
|
|
|
*/ |
|
138
|
1 |
|
public static function create($body = '') |
|
139
|
|
|
{ |
|
140
|
1 |
|
return new static($body); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|