|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package Cadmium\Framework\Validate |
|
5
|
|
|
* @author Anton Romanov |
|
6
|
|
|
* @copyright Copyright (c) 2015-2017, Anton Romanov |
|
7
|
|
|
* @link http://cadmium-cms.com |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace { |
|
11
|
|
|
|
|
12
|
|
|
abstract class Validate { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Validate a boolean value |
|
16
|
|
|
* |
|
17
|
|
|
* @return bool : true for "1", "true", "on" and "yes", otherwise false |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
public static function boolean($value) : bool { |
|
21
|
|
|
|
|
22
|
|
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Validate an ip address |
|
27
|
|
|
* |
|
28
|
|
|
* @return string|false : the filtered data or false if the filter fails |
|
29
|
|
|
*/ |
|
30
|
|
|
|
|
31
|
|
|
public static function ip(string $value) { |
|
32
|
|
|
|
|
33
|
|
|
return filter_var($value, FILTER_VALIDATE_IP); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Validate an email |
|
38
|
|
|
* |
|
39
|
|
|
* @return string|false : the filtered data or false if the filter fails |
|
40
|
|
|
*/ |
|
41
|
|
|
|
|
42
|
|
|
public static function email(string $value) { |
|
43
|
|
|
|
|
44
|
|
|
return filter_var($value, FILTER_VALIDATE_EMAIL); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Validate a regular expression |
|
49
|
|
|
* |
|
50
|
|
|
* @return string|false : the filtered data or false if the filter fails |
|
51
|
|
|
*/ |
|
52
|
|
|
|
|
53
|
|
|
public static function regex(string $value) { |
|
54
|
|
|
|
|
55
|
|
|
return filter_var($value, FILTER_VALIDATE_REGEXP); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Validate a mac address |
|
60
|
|
|
* |
|
61
|
|
|
* @return string|false : the filtered data or false if the filter fails |
|
62
|
|
|
*/ |
|
63
|
|
|
|
|
64
|
|
|
public static function mac(string $value) { |
|
65
|
|
|
|
|
66
|
|
|
return filter_var($value, FILTER_VALIDATE_MAC); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Validate an url |
|
71
|
|
|
* |
|
72
|
|
|
* @return string|false : the filtered data or false if the filter fails |
|
73
|
|
|
*/ |
|
74
|
|
|
|
|
75
|
|
|
public static function url(string $value) { |
|
76
|
|
|
|
|
77
|
|
|
return filter_var($value, FILTER_VALIDATE_URL); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|