|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Utils { |
|
4
|
|
|
|
|
5
|
|
|
use Str; |
|
6
|
|
|
|
|
7
|
|
|
class Validate extends \Validate { |
|
8
|
|
|
|
|
9
|
|
|
# Validate string using regex and length limitors |
|
10
|
|
|
|
|
11
|
|
|
private static function string(string $string, string $regex, int $min, int $max) { |
|
12
|
|
|
|
|
13
|
|
|
if (!preg_match($regex, $string)) return false; |
|
14
|
|
|
|
|
15
|
|
|
return ((Str::between($string, $min, $max)) ? $string : false); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
# Validate auth code |
|
19
|
|
|
|
|
20
|
|
|
public static function authCode(string $value) { |
|
21
|
|
|
|
|
22
|
|
|
return (preg_match(REGEX_USER_AUTH_CODE, $value) ? $code : false); |
|
|
|
|
|
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
# Validate user name |
|
26
|
|
|
|
|
27
|
|
|
public static function userName(string $value) { |
|
28
|
|
|
|
|
29
|
|
|
$min = CONFIG_USER_NAME_MIN_LENGTH; $max = CONFIG_USER_NAME_MAX_LENGTH; |
|
30
|
|
|
|
|
31
|
|
|
return self::string($value, REGEX_USER_NAME, $min, $max); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
# Validate user password |
|
35
|
|
|
|
|
36
|
|
|
public static function userPassword(string $value) { |
|
37
|
|
|
|
|
38
|
|
|
$min = CONFIG_USER_PASSWORD_MIN_LENGTH; $max = CONFIG_USER_PASSWORD_MAX_LENGTH; |
|
39
|
|
|
|
|
40
|
|
|
return self::string($value, REGEX_USER_PASSWORD, $min, $max); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
# Validate user email |
|
44
|
|
|
|
|
45
|
|
|
public static function userEmail(string $value) { |
|
46
|
|
|
|
|
47
|
|
|
return self::email($value); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
# Validate file or directory name |
|
51
|
|
|
|
|
52
|
|
|
public static function fileName(string $value) { |
|
53
|
|
|
|
|
54
|
|
|
return (preg_match(REGEX_FILE_NAME, $value) ? $name : false); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
# Validate url |
|
58
|
|
|
|
|
59
|
|
|
public static function url(string $value) { |
|
60
|
|
|
|
|
61
|
|
|
if (false === ($value = parent::url($value))) return false; |
|
62
|
|
|
|
|
63
|
|
|
if (!preg_match('/^https?:\/\//', $value)) return false; |
|
64
|
|
|
|
|
65
|
|
|
# ------------------------ |
|
66
|
|
|
|
|
67
|
|
|
return rtrim($value, '/'); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.