5
5
use Sms77 \Api \Exception \InvalidOptionalArgumentException ;
6
6
use Sms77 \Api \Exception \InvalidRequiredArgumentException ;
7
7
8
- class SmsValidator extends BaseValidator implements ValidatorInterface
9
- {
10
- public function validate ()
11
- {
8
+ class SmsValidator extends BaseValidator implements ValidatorInterface {
9
+ public function validate () {
12
10
$ this ->debug ();
13
11
$ this ->delay ();
14
12
$ this ->details ();
@@ -28,17 +26,15 @@ public function validate()
28
26
$ this ->ttl ();
29
27
}
30
28
31
- public function debug ()
32
- {
29
+ public function debug () {
33
30
$ debug = isset ($ this ->parameters ['debug ' ]) ? $ this ->parameters ['debug ' ] : null ;
34
31
35
32
if ((null !== $ debug ) && !$ this ->isValidBool ($ debug )) {
36
33
throw new InvalidOptionalArgumentException ('debug can be either 1 or 0. ' );
37
34
}
38
35
}
39
36
40
- public function delay ()
41
- {
37
+ public function delay () {
42
38
$ delay = isset ($ this ->parameters ['delay ' ]) ? $ this ->parameters ['delay ' ] : null ;
43
39
44
40
if (null !== $ delay ) {
@@ -48,31 +44,31 @@ public function delay()
48
44
49
45
if (false === strpos ($ delay , '- ' )) {
50
46
if (!$ this ->isValidUnixTimestamp ($ delay )) {
51
- throw new InvalidOptionalArgumentException ("Delay must be a valid UNIX timestamp or in the format of $ dateFormat. " );
47
+ throw new InvalidOptionalArgumentException (
48
+ "Delay must be a valid UNIX timestamp or in the format of $ dateFormat. " );
52
49
}
53
50
} else {
54
51
if (!preg_match ('/^([0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/ ' , $ hour . ': ' . $ min )) {
55
52
throw new InvalidOptionalArgumentException ('date seems to have an invalid format. ' );
56
53
}
57
54
58
55
if (!checkdate ($ month , $ day , $ year )) {
59
- throw new InvalidOptionalArgumentException ("Delay must be a valid UNIX timestamp or in the format of $ dateFormat. " );
56
+ throw new InvalidOptionalArgumentException (
57
+ "Delay must be a valid UNIX timestamp or in the format of $ dateFormat. " );
60
58
}
61
59
}
62
60
}
63
61
}
64
62
65
- public function details ()
66
- {
63
+ public function details () {
67
64
$ details = isset ($ this ->parameters ['details ' ]) ? $ this ->parameters ['details ' ] : null ;
68
65
69
66
if (null !== $ details && !$ this ->isValidBool ($ details )) {
70
67
throw new InvalidOptionalArgumentException ('details can be either 1 or 0. ' );
71
68
}
72
69
}
73
70
74
- public function label ()
75
- {
71
+ public function label () {
76
72
//TODO: max length?! there must be one.
77
73
78
74
$ label = isset ($ this ->parameters ['label ' ]) ? $ this ->parameters ['label ' ] : null ;
@@ -86,8 +82,7 @@ public function label()
86
82
}
87
83
}
88
84
89
- public function flash ()
90
- {
85
+ public function flash () {
91
86
$ flash = isset ($ this ->parameters ['flash ' ]) ? $ this ->parameters ['flash ' ] : null ;
92
87
93
88
if (null !== $ flash ) {
@@ -103,8 +98,7 @@ public function flash()
103
98
}
104
99
}
105
100
106
- public function from ()
107
- {
101
+ public function from () {
108
102
$ from = isset ($ this ->parameters ['from ' ]) ? $ this ->parameters ['from ' ] : null ;
109
103
110
104
if (null !== $ from ) {
@@ -124,50 +118,47 @@ public function from()
124
118
"Argument 'from' must be numeric. if > $ alphaNumericMax chars. " );
125
119
}
126
120
127
- if (!ctype_alnum ($ from )) {
121
+ $ allowedSpecialChars = ['/ ' , ' ' , '. ' , '- ' , '@ ' , '_ ' , '! ' , '( ' , ') ' , '+ ' , '$ ' , ', ' , '& ' ,];
122
+ if (!ctype_alnum (str_ireplace ($ allowedSpecialChars , '' , $ from ))) {
128
123
throw new InvalidOptionalArgumentException ("Argument 'from' must be alphanumeric. " );
129
124
}
130
125
}
131
126
}
132
127
133
- public function json ()
134
- {
128
+ public function json () {
135
129
$ json = isset ($ this ->parameters ['json ' ]) ? $ this ->parameters ['json ' ] : null ;
136
130
137
131
if ((null !== $ json ) && !$ this ->isValidBool ($ json )) {
138
132
throw new InvalidOptionalArgumentException ('json can be either 1 or 0. ' );
139
133
}
140
134
}
141
135
142
- public function no_reload ()
143
- {
136
+ public function no_reload () {
144
137
$ noReload = isset ($ this ->parameters ['no_reload ' ]) ? $ this ->parameters ['no_reload ' ] : null ;
145
138
146
139
if ((null !== $ noReload ) && !$ this ->isValidBool ($ noReload )) {
147
140
throw new InvalidOptionalArgumentException ('no_reload can be either 1 or 0. ' );
148
141
}
149
142
}
150
143
151
- public function performance_tracking ()
152
- {
153
- $ performanceTracking = isset ($ this ->parameters ['performance_tracking ' ]) ? $ this ->parameters ['performance_tracking ' ] : null ;
144
+ public function performance_tracking () {
145
+ $ performanceTracking =
146
+ isset ($ this ->parameters ['performance_tracking ' ]) ? $ this ->parameters ['performance_tracking ' ] : null ;
154
147
155
148
if ((null !== $ performanceTracking ) && !$ this ->isValidBool ($ performanceTracking )) {
156
149
throw new InvalidOptionalArgumentException ('performance_tracking can be either 1 or 0. ' );
157
150
}
158
151
}
159
152
160
- public function return_msg_id ()
161
- {
153
+ public function return_msg_id () {
162
154
$ returnMsgId = isset ($ this ->parameters ['return_msg_id ' ]) ? $ this ->parameters ['return_msg_id ' ] : null ;
163
155
164
156
if ((null !== $ returnMsgId ) && !$ this ->isValidBool ($ returnMsgId )) {
165
157
throw new InvalidOptionalArgumentException ('return_msg_id can be either 1 or 0. ' );
166
158
}
167
159
}
168
160
169
- public function text ()
170
- {
161
+ public function text () {
171
162
$ text = isset ($ this ->parameters ['text ' ]) ? $ this ->parameters ['text ' ] : null ;
172
163
173
164
if (null === $ text ) {
@@ -183,21 +174,21 @@ public function text()
183
174
$ maxTextLength = 1520 ;
184
175
185
176
if ($ maxTextLength < $ length ) {
186
- throw new InvalidRequiredArgumentException ("The text can not be longer than $ maxTextLength characters. " );
177
+ throw new InvalidRequiredArgumentException (
178
+ "The text can not be longer than $ maxTextLength characters. " );
187
179
}
188
180
}
189
181
190
- public function to ()
191
- {
182
+ public function to () {
192
183
$ to = isset ($ this ->parameters ['to ' ]) ? $ this ->parameters ['to ' ] : null ;
193
184
194
185
if (null === $ to ) {
195
- throw new InvalidRequiredArgumentException ('You cannot send a message without specifying a recipient. ' );
186
+ throw new InvalidRequiredArgumentException (
187
+ 'You cannot send a message without specifying a recipient. ' );
196
188
}
197
189
}
198
190
199
- public function ttl ()
200
- {
191
+ public function ttl () {
201
192
$ ttl = isset ($ this ->parameters ['ttl ' ]) ? $ this ->parameters ['ttl ' ] : null ;
202
193
203
194
if (null !== $ ttl ) {
@@ -214,13 +205,11 @@ public function ttl()
214
205
}
215
206
}
216
207
217
- public function type ()
218
- {
208
+ public function type () {
219
209
$ this ->throwOnOptionalBadType ();
220
210
}
221
211
222
- public function udh ()
223
- {
212
+ public function udh () {
224
213
$ udh = isset ($ this ->parameters ['udh ' ]) ? $ this ->parameters ['udh ' ] : null ;
225
214
226
215
if (null !== $ udh ) {
@@ -234,8 +223,7 @@ public function udh()
234
223
}
235
224
}
236
225
237
- public function unicode ()
238
- {
226
+ public function unicode () {
239
227
$ unicode = isset ($ this ->parameters ['unicode ' ]) ? $ this ->parameters ['unicode ' ] : null ;
240
228
241
229
if (null !== $ unicode ) {
@@ -249,8 +237,7 @@ public function unicode()
249
237
}
250
238
}
251
239
252
- public function utf8 ()
253
- {
240
+ public function utf8 () {
254
241
$ utf8 = isset ($ this ->parameters ['utf8 ' ]) ? $ this ->parameters ['utf8 ' ] : null ;
255
242
256
243
if ((null !== $ utf8 ) && !$ this ->isValidBool ($ utf8 )) {
0 commit comments