-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPHPSanitizer.php
90 lines (77 loc) · 2.13 KB
/
PHPSanitizer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* Created by PhpStorm.
* User: leodaido
* Date: 1/14/15
* Time: 3:48 PM
*/
class PHPSanitizer {
const PARANOID = 1;
const SQL = 2;
const SYSTEM = 4;
const HTML = 8;
const INT = 16;
const FLOAT = 32;
const LDAP = 64;
const UTF8 = 128;
const CUSTOM = 256;
private $type = PHPSanitizer::PARANOID;
private $sanitizer;
private $custom_name;
public static function getInstance(){
static $instance = null;
if($instance===null){
$instance = new PHPSanitizer();
}
return $instance;
}
public function validate($string){
return $this->sanitizer->validate($string);
}
public function cleanup($string){
return $this->sanitizer->cleanup($string);
}
public function setType($type=PHPSanitizer::PARANOID, $custom_name=null, $base_path=null){
if($type == PHPSanitizer::CUSTOM && is_null($custom_name)){
throw new InvalidCustomNameException("Custom type required custom name.");
}
$this->type = $type;
$this->custom_name = $custom_name;
try{
$this->sanitizer = SanitizerFactory::build($this->type,$this->custom_name, $base_path);
}catch (Exception $e){
throw $e;
}
}
// Protected Scope
protected function __construct(){
require_once('ClassLoader.php');
ClassLoader::Register();
ClassLoader::Load('SanitizerFactory', dirname(__FILE__).'/');
ClassLoader::Load('InvalidCustomNameException', dirname(__FILE__).'/exceptions/');
try{
$this->sanitizer = SanitizerFactory::build($this->type,null,null);
}catch (InvalidCustomNameException $e){
throw $e;
}
}
// Private Scope
/**
* Private clone method to prevent cloning of the instance of the
* *PHPSanitizer* instance.
*
* @return void
*/
private function __clone()
{
}
/**
* Private unserialize method to prevent unserializing of the *PHPSanitizer*
* instance.
*
* @return void
*/
private function __wakeup()
{
}
}