|
1
|
|
|
<?php |
|
2
|
|
|
namespace Sender; |
|
3
|
|
|
|
|
4
|
|
|
use DateTime; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* This Class provide validation Functions |
|
8
|
|
|
* |
|
9
|
|
|
* @package Msg91 SMS&OTP package |
|
10
|
|
|
* @author VenkatS <[email protected]> |
|
11
|
|
|
* @link https://github.com/tesark/msg91-php |
|
12
|
|
|
* @license MIT |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
class Validation |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Check is String type |
|
19
|
|
|
* @param string $value |
|
20
|
|
|
* |
|
21
|
|
|
* @return bool |
|
22
|
|
|
*/ |
|
23
|
98 |
|
public static function isString($value) |
|
24
|
|
|
{ |
|
25
|
98 |
|
return is_string($value); |
|
26
|
|
|
} |
|
27
|
|
|
/** |
|
28
|
|
|
* Check is integer type |
|
29
|
|
|
* @param int $value |
|
30
|
|
|
* |
|
31
|
|
|
* @return bool |
|
32
|
|
|
*/ |
|
33
|
102 |
|
public static function isInteger($value) |
|
34
|
|
|
{ |
|
35
|
102 |
|
return is_int($value); |
|
36
|
|
|
} |
|
37
|
|
|
/** |
|
38
|
|
|
* Check is Numeric type |
|
39
|
|
|
* @param string $value |
|
40
|
|
|
* |
|
41
|
|
|
* @return bool |
|
42
|
|
|
*/ |
|
43
|
14 |
|
public static function isNumeric($value) |
|
44
|
|
|
{ |
|
45
|
14 |
|
return is_numeric($value); |
|
46
|
|
|
} |
|
47
|
|
|
/** |
|
48
|
|
|
* This function for check auth key present or not |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $authKey |
|
51
|
|
|
* @return bool |
|
52
|
|
|
*/ |
|
53
|
102 |
|
public static function isAuthKey($authKey) |
|
54
|
|
|
{ |
|
55
|
102 |
|
if (isset($authKey) && is_string($authKey)) { |
|
56
|
101 |
|
return true; |
|
57
|
|
|
} else { |
|
58
|
1 |
|
return false; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
/** |
|
62
|
|
|
* Check validate date time format |
|
63
|
|
|
* @param string $date |
|
64
|
|
|
* |
|
65
|
|
|
* @return bool |
|
66
|
|
|
*/ |
|
67
|
22 |
|
public static function isValidDateFirstFormat($date, $format = 'Y-m-d h:i:s') |
|
68
|
|
|
{ |
|
69
|
22 |
|
$date = trim($date); |
|
70
|
22 |
|
$d = DateTime::createFromFormat($format, $date); |
|
71
|
22 |
|
return $d && $d->format($format) == $date; |
|
72
|
|
|
} |
|
73
|
|
|
/** |
|
74
|
|
|
* @param string $date |
|
75
|
|
|
* |
|
76
|
|
|
* @return bool |
|
77
|
|
|
*/ |
|
78
|
22 |
|
public static function isValidDateSecondFormat($date, $format = 'Y/m/d h:i:s') |
|
79
|
|
|
{ |
|
80
|
22 |
|
$date = trim($date); |
|
81
|
22 |
|
$d = DateTime::createFromFormat($format, $date); |
|
82
|
22 |
|
return $d && $d->format($format) == $date; |
|
83
|
|
|
} |
|
84
|
|
|
/** |
|
85
|
|
|
* Test Unix Timestamp |
|
86
|
|
|
* @param string $timestamp |
|
87
|
|
|
* |
|
88
|
|
|
* @return bool |
|
89
|
|
|
*/ |
|
90
|
22 |
|
public static function isValidTimeStamp($timestamp) |
|
91
|
|
|
{ |
|
92
|
22 |
|
if (is_int($timestamp)) { |
|
|
|
|
|
|
93
|
4 |
|
$timestamp = (int) trim($timestamp); |
|
94
|
4 |
|
$max = strtotime("+1 minutes"); |
|
95
|
4 |
|
$min = strtotime("-15 minutes"); |
|
96
|
4 |
|
if ($min < $timestamp && $max > $timestamp) { |
|
97
|
1 |
|
return true; |
|
98
|
|
|
} else { |
|
99
|
3 |
|
return false; |
|
100
|
|
|
} |
|
101
|
|
|
} else { |
|
102
|
19 |
|
return false; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
/** |
|
106
|
|
|
* This function get array the size |
|
107
|
|
|
* @param array $value |
|
108
|
|
|
* |
|
109
|
|
|
* return int Size fo the array |
|
110
|
|
|
*/ |
|
111
|
2 |
|
public static function getSize($value) |
|
112
|
|
|
{ |
|
113
|
2 |
|
if (is_array($value)) { |
|
|
|
|
|
|
114
|
1 |
|
return sizeof($value); |
|
115
|
|
|
} else { |
|
116
|
1 |
|
return false; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|