|
1
|
|
|
<?php |
|
2
|
|
|
namespace Sender\Traits; |
|
3
|
|
|
|
|
4
|
|
|
use Sender\Validation; |
|
5
|
|
|
use Sender\MobileNumber; |
|
6
|
|
|
use Sender\Sms\SmsDefineClass; |
|
7
|
|
|
use Sender\Sms\SmsBuildClass; |
|
8
|
|
|
use Sender\ExceptionClass\ParameterException; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* This trait for SMS OTP FUNCTIONS |
|
12
|
|
|
* |
|
13
|
|
|
* @package Msg91 SMS&OTP package |
|
14
|
|
|
* @author VenkatS <[email protected]> |
|
15
|
|
|
* @link https://github.com/tesark/msg91-php |
|
16
|
|
|
* @license MIT |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
trait SmsBuildSupportTrait |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* This function for check afterminutes |
|
23
|
|
|
* @param int $category |
|
24
|
|
|
* @param string $key |
|
25
|
|
|
* @param array $buildSmsData |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
4 |
|
public function checkAfterMinutes($category, $key, $value, $buildSmsData) |
|
29
|
|
|
{ |
|
30
|
4 |
|
if ($this->isVaildAfterMinutes($value)) { |
|
|
|
|
|
|
31
|
|
|
$buildSmsData = $this->buildData($category, $key, $value, $buildSmsData); |
|
|
|
|
|
|
32
|
|
|
return $buildSmsData; |
|
33
|
|
|
} else { |
|
34
|
4 |
|
$message = "Allowed between 10 to 20000 mintutes"; |
|
35
|
4 |
|
throw ParameterException::invalidInput("afterminutes", "int", $value, $message); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
/** |
|
39
|
|
|
* This function for simplify afterminutes |
|
40
|
|
|
* @param int $category |
|
41
|
|
|
* @param string $key |
|
42
|
|
|
* @param array $buildSmsData |
|
43
|
|
|
* |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
8 |
|
public function simplifyAfterMinutes($category, $key, $buildSmsData, $value) |
|
47
|
|
|
{ |
|
48
|
8 |
|
if ($this->isInterger($value)) { |
|
|
|
|
|
|
49
|
4 |
|
$buildSmsData = $this->checkAfterMinutes($category, $key, $value, $buildSmsData); |
|
50
|
|
|
} else { |
|
51
|
4 |
|
throw ParameterException::invalidArrtibuteType($key, "int", $value); |
|
52
|
|
|
} |
|
53
|
|
|
return $buildSmsData; |
|
54
|
|
|
} |
|
55
|
|
|
/** |
|
56
|
|
|
* This function for Add mobile number to XML |
|
57
|
|
|
* @param array $xmlDoc |
|
58
|
|
|
* @param array $smsTag |
|
59
|
|
|
* |
|
60
|
|
|
*/ |
|
61
|
|
|
public function addMobileToXml($xmlDoc, $smsTag, $result) |
|
62
|
|
|
{ |
|
63
|
|
|
if (!empty($result) && $result['value'] == true) { |
|
64
|
|
|
$mobiles = $result['mobile']; |
|
65
|
|
|
$len = Validation::getSize($mobiles); |
|
66
|
|
|
for ($k = 0; $k < $len; $k++) { |
|
67
|
|
|
$addressTag = $smsTag->appendChild($xmlDoc->createElement("ADDRESS")); |
|
68
|
|
|
$childAttr = $xmlDoc->createAttribute("TO"); |
|
69
|
|
|
$childText = $xmlDoc->createTextNode($mobiles[$k]); |
|
70
|
|
|
$addressTag->appendChild($childAttr)->appendChild($childText); |
|
71
|
|
|
} |
|
72
|
|
|
} else { |
|
73
|
|
|
$message = "string comma seperate values you given:".$result['mobile']; |
|
74
|
|
|
throw ParameterException::invalidInput("mobile", "string", $result['mobile'], $message); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
/** |
|
78
|
|
|
* This function for sms array Build with mobilenumbers |
|
79
|
|
|
* @param array $buildSmsData |
|
80
|
|
|
* @param int $category |
|
81
|
|
|
* |
|
82
|
|
|
* @throws ParameterException missing parameters or return empty |
|
83
|
|
|
* @return array |
|
84
|
|
|
*/ |
|
85
|
80 |
|
public function addMobile($buildSmsData, $category) |
|
86
|
|
|
{ |
|
87
|
80 |
|
$key = ''; |
|
88
|
80 |
|
if ($category === 1) { |
|
89
|
80 |
|
$key = 'mobiles'; |
|
90
|
|
|
} else { |
|
91
|
|
|
$key = 'mobile'; |
|
92
|
|
|
} |
|
93
|
80 |
|
$value = $this->categoryWiseAddedMobile(); |
|
|
|
|
|
|
94
|
80 |
|
$buildSmsData = $this->checkIntegerOrString($key, $value, $buildSmsData, $category); |
|
|
|
|
|
|
95
|
80 |
|
return $buildSmsData; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|