Skip to content

Commit 4cd236d

Browse files
committed
added validator for validate_for_voice
1 parent e34605a commit 4cd236d

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

src/Client.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Sms77\Api\Validator\ContactsValidator;
66
use Sms77\Api\Validator\LookupValidator;
77
use Sms77\Api\Validator\SmsValidator;
8+
use Sms77\Api\Validator\ValidateForVoiceValidator;
89
use Sms77\Api\Validator\VoiceValidator;
910

1011
class Client
@@ -81,14 +82,13 @@ function status($msgId)
8182
return $this->request("status", $options);
8283
}
8384

84-
/*TODO: add add validation*/
8585
function validateForVoice($number, array $extra = [])
8686
{
87-
$required = [
87+
$options = $this->buildOptions([
8888
"number" => $number,
89-
];
89+
], $extra);
9090

91-
$options = array_merge($required, $extra);
91+
(new ValidateForVoiceValidator($options))->validate();
9292

9393
return $this->request("validate_for_voice", $options);
9494
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
}

0 commit comments

Comments
 (0)