File tree Expand file tree Collapse file tree 2 files changed +43
-4
lines changed Expand file tree Collapse file tree 2 files changed +43
-4
lines changed Original file line number Diff line number Diff line change 5
5
use Sms77 \Api \Validator \ContactsValidator ;
6
6
use Sms77 \Api \Validator \LookupValidator ;
7
7
use Sms77 \Api \Validator \SmsValidator ;
8
+ use Sms77 \Api \Validator \ValidateForVoiceValidator ;
8
9
use Sms77 \Api \Validator \VoiceValidator ;
9
10
10
11
class Client
@@ -81,14 +82,13 @@ function status($msgId)
81
82
return $ this ->request ("status " , $ options );
82
83
}
83
84
84
- /*TODO: add add validation*/
85
85
function validateForVoice ($ number , array $ extra = [])
86
86
{
87
- $ required = [
87
+ $ options = $ this -> buildOptions ( [
88
88
"number " => $ number ,
89
- ];
89
+ ], $ extra ) ;
90
90
91
- $ options = array_merge ( $ required , $ extra );
91
+ ( new ValidateForVoiceValidator ( $ options ))-> validate ( );
92
92
93
93
return $ this ->request ("validate_for_voice " , $ options );
94
94
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Sms77 \Api \Validator ;
4
+
5
+ use Exception ;
6
+
7
+ class ValidateForVoiceValidator extends BaseValidator implements ValidatorInterface
8
+ {
9
+ function __construct (array $ parameters )
10
+ {
11
+ parent ::__construct ($ parameters );
12
+ }
13
+
14
+ function validate ()
15
+ {
16
+ $ this ->callback ();
17
+ $ this ->number ();
18
+ }
19
+
20
+ function callback ()
21
+ {
22
+ $ callback = isset ($ this ->parameters ["callback " ]) ? $ this ->parameters ["callback " ] : null ;
23
+
24
+ if (null !== $ callback ) {
25
+ if (filter_var ($ callback , FILTER_VALIDATE_URL )) {
26
+ throw new Exception ("The optional parameter callback is not a valid URL. " );
27
+ }
28
+ }
29
+ }
30
+
31
+ function number ()
32
+ {
33
+ $ number = isset ($ this ->parameters ["number " ]) ? $ this ->parameters ["number " ] : null ;
34
+
35
+ if (!strlen ($ number )) {
36
+ throw new Exception ("The required parameter number is missing. " );
37
+ }
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments