|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* KNUT7 K7F (https://marciozebedeu.com/) |
|
6
|
|
|
* KNUT7 K7F (tm) : Rapid Development Framework (https://marciozebedeu.com/) |
|
7
|
|
|
* |
|
8
|
|
|
* Licensed under The MIT License |
|
9
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
|
10
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
11
|
|
|
* |
|
12
|
|
|
* @link https://github.com/knut7/framework/ for the canonical source repository |
|
13
|
|
|
* @copyright (c) 2015. KNUT7 Software Technologies AO Inc. (https://marciozebedeu.com/) |
|
14
|
|
|
* @license https://marciozebedeu.com/license/new-bsd New BSD License |
|
15
|
|
|
* @author Marcio Zebedeu - [email protected] |
|
16
|
|
|
* @version 1.0.2 |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Ballybran\Helpers\Security; |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class ValidateTypes |
|
24
|
|
|
* @package Ballybran\Helpers\Security |
|
25
|
|
|
*/ |
|
26
|
|
|
class ValidateTypes |
|
27
|
|
|
{ |
|
28
|
|
|
|
|
29
|
|
|
public static function getSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") |
|
30
|
|
|
{ |
|
31
|
|
|
|
|
32
|
|
|
$theValue = function_exists("htmlspecialchars") ? htmlspecialchars($theValue) : $theValue; |
|
33
|
|
|
|
|
34
|
|
|
switch ($theType) { |
|
35
|
|
|
case "string": |
|
36
|
|
|
if (!is_string($theValue)) { |
|
37
|
|
|
return null; |
|
38
|
|
|
} |
|
39
|
|
|
return strip_tags("$theValue"); |
|
40
|
|
|
case "email": |
|
41
|
|
|
if (!is_string($theValue)) { |
|
42
|
|
|
return null; |
|
43
|
|
|
} |
|
44
|
|
|
return filter_var($theValue, FILTER_VALIDATE_EMAIL); |
|
45
|
|
|
break; |
|
|
|
|
|
|
46
|
|
|
case "long": |
|
47
|
|
|
case "int": |
|
48
|
|
|
if (!is_numeric($theValue)) { |
|
49
|
|
|
return null; |
|
50
|
|
|
} |
|
51
|
|
|
return intval($theValue); |
|
52
|
|
|
break; |
|
53
|
|
|
case "double": |
|
54
|
|
|
if (!is_double($theValue)) { |
|
55
|
|
|
return null; |
|
56
|
|
|
} |
|
57
|
|
|
return floatval($theValue); |
|
58
|
|
|
break; |
|
59
|
|
|
case "date": |
|
60
|
|
|
|
|
61
|
|
|
$theValue = ($theValue != "") ? "" . $theValue . "" : null; |
|
62
|
|
|
break; |
|
63
|
|
|
case "url": |
|
64
|
|
|
if (!is_string($theValue)) { |
|
65
|
|
|
return null; |
|
66
|
|
|
} |
|
67
|
|
|
return filter_var($theValue, FILTER_VALIDATE_URL); |
|
68
|
|
|
break; |
|
69
|
|
|
case "domain": |
|
70
|
|
|
if (!is_string($theValue)) { |
|
71
|
|
|
return null; |
|
72
|
|
|
} |
|
73
|
|
|
return filter_var($theValue, FILTER_VALIDATE_DOMAIN); |
|
74
|
|
|
break; |
|
75
|
|
|
case "ip": |
|
76
|
|
|
if (!is_double($theValue)) { |
|
77
|
|
|
return null; |
|
78
|
|
|
} |
|
79
|
|
|
return filter_var($theValue, FILTER_VALIDATE_IP); |
|
80
|
|
|
break; |
|
81
|
|
|
case "defined": |
|
82
|
|
|
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; |
|
83
|
|
|
break; |
|
84
|
|
|
} |
|
85
|
|
|
return $theValue; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
} |
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.