@@ -27,9 +27,9 @@ |
||
27 | 27 | |
28 | 28 | interface Validator_Base { |
29 | 29 | |
30 | - public function isValide ($value) : bool; |
|
30 | + public function isValide ($value) : bool; |
|
31 | 31 | |
32 | - public function validate ($value); |
|
32 | + public function validate ($value); |
|
33 | 33 | |
34 | 34 | } |
35 | 35 |
@@ -27,9 +27,9 @@ |
||
27 | 27 | |
28 | 28 | interface Validator_Base { |
29 | 29 | |
30 | - public function isValide ($value) : bool; |
|
30 | + public function isValide($value) : bool; |
|
31 | 31 | |
32 | - public function validate ($value); |
|
32 | + public function validate($value); |
|
33 | 33 | |
34 | 34 | } |
35 | 35 |
@@ -28,26 +28,26 @@ |
||
28 | 28 | */ |
29 | 29 | class Validator_String implements Validator_Base { |
30 | 30 | |
31 | - public function isValide($value) : bool { |
|
32 | - $validated_str = $this->validate($value); |
|
31 | + public function isValide($value) : bool { |
|
32 | + $validated_str = $this->validate($value); |
|
33 | 33 | |
34 | - return strcmp($value, $validated_str) === 0; |
|
35 | - } |
|
34 | + return strcmp($value, $validated_str) === 0; |
|
35 | + } |
|
36 | 36 | |
37 | - public function validate($value) : string { |
|
38 | - //escape string |
|
39 | - //$value = Database::getInstance()->escape($value); |
|
37 | + public function validate($value) : string { |
|
38 | + //escape string |
|
39 | + //$value = Database::getInstance()->escape($value); |
|
40 | 40 | |
41 | - //remove html entities |
|
42 | - $value = htmlspecialchars($value, ENT_QUOTES, "UTF-8");//htmlentities($value, null, "UTF-8"); |
|
41 | + //remove html entities |
|
42 | + $value = htmlspecialchars($value, ENT_QUOTES, "UTF-8");//htmlentities($value, null, "UTF-8"); |
|
43 | 43 | |
44 | - return $value; |
|
45 | - } |
|
44 | + return $value; |
|
45 | + } |
|
46 | 46 | |
47 | - public static function get (string $value) : string { |
|
48 | - $obj = new Validator_String(); |
|
49 | - return $obj->validate($value); |
|
50 | - } |
|
47 | + public static function get (string $value) : string { |
|
48 | + $obj = new Validator_String(); |
|
49 | + return $obj->validate($value); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | } |
53 | 53 |
@@ -39,12 +39,12 @@ |
||
39 | 39 | //$value = Database::getInstance()->escape($value); |
40 | 40 | |
41 | 41 | //remove html entities |
42 | - $value = htmlspecialchars($value, ENT_QUOTES, "UTF-8");//htmlentities($value, null, "UTF-8"); |
|
42 | + $value = htmlspecialchars($value, ENT_QUOTES, "UTF-8"); //htmlentities($value, null, "UTF-8"); |
|
43 | 43 | |
44 | 44 | return $value; |
45 | 45 | } |
46 | 46 | |
47 | - public static function get (string $value) : string { |
|
47 | + public static function get(string $value) : string { |
|
48 | 48 | $obj = new Validator_String(); |
49 | 49 | return $obj->validate($value); |
50 | 50 | } |
@@ -27,19 +27,19 @@ |
||
27 | 27 | |
28 | 28 | class Validator_Filename implements Validator_Base { |
29 | 29 | |
30 | - public function isValide ($value): bool { |
|
31 | - return ctype_alnum($value); |
|
32 | - } |
|
33 | - |
|
34 | - public function validate ($value) : string { |
|
35 | - //remove all characters except except a-z, A-Z and 0-9 |
|
36 | - return preg_replace("/[^a-zA-Z0-9]+/", "", $value); |
|
37 | - } |
|
38 | - |
|
39 | - public static function get (string $value) : string { |
|
40 | - $obj = new Validator_Filename(); |
|
41 | - return $obj->validate($value); |
|
42 | - } |
|
30 | + public function isValide ($value): bool { |
|
31 | + return ctype_alnum($value); |
|
32 | + } |
|
33 | + |
|
34 | + public function validate ($value) : string { |
|
35 | + //remove all characters except except a-z, A-Z and 0-9 |
|
36 | + return preg_replace("/[^a-zA-Z0-9]+/", "", $value); |
|
37 | + } |
|
38 | + |
|
39 | + public static function get (string $value) : string { |
|
40 | + $obj = new Validator_Filename(); |
|
41 | + return $obj->validate($value); |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | ?> |
@@ -27,16 +27,16 @@ |
||
27 | 27 | |
28 | 28 | class Validator_Filename implements Validator_Base { |
29 | 29 | |
30 | - public function isValide ($value): bool { |
|
30 | + public function isValide($value): bool { |
|
31 | 31 | return ctype_alnum($value); |
32 | 32 | } |
33 | 33 | |
34 | - public function validate ($value) : string { |
|
34 | + public function validate($value) : string { |
|
35 | 35 | //remove all characters except except a-z, A-Z and 0-9 |
36 | 36 | return preg_replace("/[^a-zA-Z0-9]+/", "", $value); |
37 | 37 | } |
38 | 38 | |
39 | - public static function get (string $value) : string { |
|
39 | + public static function get(string $value) : string { |
|
40 | 40 | $obj = new Validator_Filename(); |
41 | 41 | return $obj->validate($value); |
42 | 42 | } |
@@ -27,39 +27,39 @@ |
||
27 | 27 | |
28 | 28 | class Validator_Color implements Validator_Base { |
29 | 29 | |
30 | - //https://code.hyperspatial.com/all-code/php-code/verify-hex-color-string/ |
|
30 | + //https://code.hyperspatial.com/all-code/php-code/verify-hex-color-string/ |
|
31 | 31 | |
32 | - public function isValide ($value): bool { |
|
33 | - if(preg_match('/^#[a-f0-9]{6}$/i', $value)) { //hex color is valid |
|
34 | - //Verified hex color |
|
35 | - return true; |
|
36 | - } else if(preg_match('/^[a-f0-9]{6}$/i', $value)) { |
|
37 | - //Check for a hex color string without hash 'c1c2b4' |
|
38 | - //hex color is valid |
|
32 | + public function isValide ($value): bool { |
|
33 | + if(preg_match('/^#[a-f0-9]{6}$/i', $value)) { //hex color is valid |
|
34 | + //Verified hex color |
|
35 | + return true; |
|
36 | + } else if(preg_match('/^[a-f0-9]{6}$/i', $value)) { |
|
37 | + //Check for a hex color string without hash 'c1c2b4' |
|
38 | + //hex color is valid |
|
39 | 39 | |
40 | - //$fix_color = '#' . $value; |
|
40 | + //$fix_color = '#' . $value; |
|
41 | 41 | |
42 | - return true; |
|
43 | - } |
|
42 | + return true; |
|
43 | + } |
|
44 | 44 | |
45 | - return false; |
|
46 | - } |
|
45 | + return false; |
|
46 | + } |
|
47 | 47 | |
48 | - public function validate ($value) { |
|
49 | - if(preg_match('/^#[a-f0-9]{6}$/i', $value)) { //hex color is valid |
|
50 | - //Verified hex color |
|
51 | - return $value; |
|
52 | - } else if(preg_match('/^[a-f0-9]{6}$/i', $value)) { |
|
53 | - //Check for a hex color string without hash 'c1c2b4' |
|
54 | - //hex color is valid |
|
48 | + public function validate ($value) { |
|
49 | + if(preg_match('/^#[a-f0-9]{6}$/i', $value)) { //hex color is valid |
|
50 | + //Verified hex color |
|
51 | + return $value; |
|
52 | + } else if(preg_match('/^[a-f0-9]{6}$/i', $value)) { |
|
53 | + //Check for a hex color string without hash 'c1c2b4' |
|
54 | + //hex color is valid |
|
55 | 55 | |
56 | - $fix_color = '#' . $value; |
|
56 | + $fix_color = '#' . $value; |
|
57 | 57 | |
58 | - return $fix_color; |
|
59 | - } |
|
58 | + return $fix_color; |
|
59 | + } |
|
60 | 60 | |
61 | - throw new Exception("method isnt implemented yet."); |
|
62 | - } |
|
61 | + throw new Exception("method isnt implemented yet."); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | } |
65 | 65 |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | |
30 | 30 | //https://code.hyperspatial.com/all-code/php-code/verify-hex-color-string/ |
31 | 31 | |
32 | - public function isValide ($value): bool { |
|
33 | - if(preg_match('/^#[a-f0-9]{6}$/i', $value)) { //hex color is valid |
|
32 | + public function isValide($value): bool { |
|
33 | + if (preg_match('/^#[a-f0-9]{6}$/i', $value)) { //hex color is valid |
|
34 | 34 | //Verified hex color |
35 | 35 | return true; |
36 | - } else if(preg_match('/^[a-f0-9]{6}$/i', $value)) { |
|
36 | + } else if (preg_match('/^[a-f0-9]{6}$/i', $value)) { |
|
37 | 37 | //Check for a hex color string without hash 'c1c2b4' |
38 | 38 | //hex color is valid |
39 | 39 | |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | return false; |
46 | 46 | } |
47 | 47 | |
48 | - public function validate ($value) { |
|
49 | - if(preg_match('/^#[a-f0-9]{6}$/i', $value)) { //hex color is valid |
|
48 | + public function validate($value) { |
|
49 | + if (preg_match('/^#[a-f0-9]{6}$/i', $value)) { //hex color is valid |
|
50 | 50 | //Verified hex color |
51 | 51 | return $value; |
52 | - } else if(preg_match('/^[a-f0-9]{6}$/i', $value)) { |
|
52 | + } else if (preg_match('/^[a-f0-9]{6}$/i', $value)) { |
|
53 | 53 | //Check for a hex color string without hash 'c1c2b4' |
54 | 54 | //hex color is valid |
55 | 55 |
@@ -27,24 +27,24 @@ |
||
27 | 27 | |
28 | 28 | class Validator_Token implements Validator_Base { |
29 | 29 | |
30 | - protected static $instance = null; |
|
30 | + protected static $instance = null; |
|
31 | 31 | |
32 | - public function isValide ($value): bool { |
|
33 | - return $value === $this->validate($value); |
|
34 | - } |
|
32 | + public function isValide ($value): bool { |
|
33 | + return $value === $this->validate($value); |
|
34 | + } |
|
35 | 35 | |
36 | - public function validate ($value) : string { |
|
37 | - //remove all characters except except a-z, A-Z and 0-9 |
|
38 | - return preg_replace("/[^a-zA-Z_0-9]+/", "", $value); |
|
39 | - } |
|
36 | + public function validate ($value) : string { |
|
37 | + //remove all characters except except a-z, A-Z and 0-9 |
|
38 | + return preg_replace("/[^a-zA-Z_0-9]+/", "", $value); |
|
39 | + } |
|
40 | 40 | |
41 | - public static function get (string $value) : string { |
|
42 | - if (self::$instance == null) { |
|
43 | - self::$instance = new Validator_Token(); |
|
44 | - } |
|
41 | + public static function get (string $value) : string { |
|
42 | + if (self::$instance == null) { |
|
43 | + self::$instance = new Validator_Token(); |
|
44 | + } |
|
45 | 45 | |
46 | - return self::$instance->validate($value); |
|
47 | - } |
|
46 | + return self::$instance->validate($value); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | } |
50 | 50 |
@@ -29,16 +29,16 @@ |
||
29 | 29 | |
30 | 30 | protected static $instance = null; |
31 | 31 | |
32 | - public function isValide ($value): bool { |
|
32 | + public function isValide($value): bool { |
|
33 | 33 | return $value === $this->validate($value); |
34 | 34 | } |
35 | 35 | |
36 | - public function validate ($value) : string { |
|
36 | + public function validate($value) : string { |
|
37 | 37 | //remove all characters except except a-z, A-Z and 0-9 |
38 | 38 | return preg_replace("/[^a-zA-Z_0-9]+/", "", $value); |
39 | 39 | } |
40 | 40 | |
41 | - public static function get (string $value) : string { |
|
41 | + public static function get(string $value) : string { |
|
42 | 42 | if (self::$instance == null) { |
43 | 43 | self::$instance = new Validator_Token(); |
44 | 44 | } |
@@ -27,27 +27,27 @@ |
||
27 | 27 | |
28 | 28 | class Validator_Mail implements Validator_Base { |
29 | 29 | |
30 | - protected static $instance = null; |
|
30 | + protected static $instance = null; |
|
31 | 31 | |
32 | - public function isValide ($value): bool { |
|
33 | - return filter_var($value, FILTER_VALIDATE_EMAIL) !== false; |
|
34 | - } |
|
32 | + public function isValide ($value): bool { |
|
33 | + return filter_var($value, FILTER_VALIDATE_EMAIL) !== false; |
|
34 | + } |
|
35 | 35 | |
36 | - public function validate ($value) : string { |
|
37 | - if (!$this->isValide($value)) { |
|
38 | - throw new SecurityException("given mail '" . htmlentities($value) . "' isnt a valide mail."); |
|
39 | - } |
|
36 | + public function validate ($value) : string { |
|
37 | + if (!$this->isValide($value)) { |
|
38 | + throw new SecurityException("given mail '" . htmlentities($value) . "' isnt a valide mail."); |
|
39 | + } |
|
40 | 40 | |
41 | - return filter_var($value, FILTER_VALIDATE_EMAIL); |
|
42 | - } |
|
41 | + return filter_var($value, FILTER_VALIDATE_EMAIL); |
|
42 | + } |
|
43 | 43 | |
44 | - public static function get (string $value) : string { |
|
45 | - if (self::$instance == null) { |
|
46 | - self::$instance = new Validator_Mail(); |
|
47 | - } |
|
44 | + public static function get (string $value) : string { |
|
45 | + if (self::$instance == null) { |
|
46 | + self::$instance = new Validator_Mail(); |
|
47 | + } |
|
48 | 48 | |
49 | - return self::$instance->validate($value); |
|
50 | - } |
|
49 | + return self::$instance->validate($value); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | } |
53 | 53 |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | |
30 | 30 | protected static $instance = null; |
31 | 31 | |
32 | - public function isValide ($value): bool { |
|
32 | + public function isValide($value): bool { |
|
33 | 33 | return filter_var($value, FILTER_VALIDATE_EMAIL) !== false; |
34 | 34 | } |
35 | 35 | |
36 | - public function validate ($value) : string { |
|
36 | + public function validate($value) : string { |
|
37 | 37 | if (!$this->isValide($value)) { |
38 | 38 | throw new SecurityException("given mail '" . htmlentities($value) . "' isnt a valide mail."); |
39 | 39 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | return filter_var($value, FILTER_VALIDATE_EMAIL); |
42 | 42 | } |
43 | 43 | |
44 | - public static function get (string $value) : string { |
|
44 | + public static function get(string $value) : string { |
|
45 | 45 | if (self::$instance == null) { |
46 | 46 | self::$instance = new Validator_Mail(); |
47 | 47 | } |
@@ -27,24 +27,24 @@ |
||
27 | 27 | |
28 | 28 | class Validator_AlphaNumeric implements Validator_Base { |
29 | 29 | |
30 | - protected static $instance = null; |
|
30 | + protected static $instance = null; |
|
31 | 31 | |
32 | - public function isValide ($value): bool { |
|
33 | - return ctype_alnum($value); |
|
34 | - } |
|
32 | + public function isValide ($value): bool { |
|
33 | + return ctype_alnum($value); |
|
34 | + } |
|
35 | 35 | |
36 | - public function validate ($value) : string { |
|
37 | - //remove all characters except except a-z, A-Z and 0-9 |
|
38 | - return preg_replace("/[^a-zA-Z0-9]+/", "", $value); |
|
39 | - } |
|
36 | + public function validate ($value) : string { |
|
37 | + //remove all characters except except a-z, A-Z and 0-9 |
|
38 | + return preg_replace("/[^a-zA-Z0-9]+/", "", $value); |
|
39 | + } |
|
40 | 40 | |
41 | - public static function get (string $value) : string { |
|
42 | - if (self::$instance == null) { |
|
43 | - self::$instance = new Validator_AlphaNumeric(); |
|
44 | - } |
|
41 | + public static function get (string $value) : string { |
|
42 | + if (self::$instance == null) { |
|
43 | + self::$instance = new Validator_AlphaNumeric(); |
|
44 | + } |
|
45 | 45 | |
46 | - return self::$instance->validate($value); |
|
47 | - } |
|
46 | + return self::$instance->validate($value); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | } |
50 | 50 |
@@ -29,16 +29,16 @@ |
||
29 | 29 | |
30 | 30 | protected static $instance = null; |
31 | 31 | |
32 | - public function isValide ($value): bool { |
|
32 | + public function isValide($value): bool { |
|
33 | 33 | return ctype_alnum($value); |
34 | 34 | } |
35 | 35 | |
36 | - public function validate ($value) : string { |
|
36 | + public function validate($value) : string { |
|
37 | 37 | //remove all characters except except a-z, A-Z and 0-9 |
38 | 38 | return preg_replace("/[^a-zA-Z0-9]+/", "", $value); |
39 | 39 | } |
40 | 40 | |
41 | - public static function get (string $value) : string { |
|
41 | + public static function get(string $value) : string { |
|
42 | 42 | if (self::$instance == null) { |
43 | 43 | self::$instance = new Validator_AlphaNumeric(); |
44 | 44 | } |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class SecurityException extends Exception{ |
|
3 | +class SecurityException extends Exception { |
|
4 | 4 | |
5 | 5 | } |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class ConfigurationException extends Exception{ |
|
3 | +class ConfigurationException extends Exception { |
|
4 | 4 | |
5 | 5 | } |