1 | <?php |
||
11 | class Sanitise |
||
12 | { |
||
13 | |||
14 | private $is_valid = null; |
||
15 | private $_sanitised = null; |
||
16 | private $filters; |
||
17 | private $input; |
||
18 | private $output; |
||
19 | private $strings; |
||
20 | private $urlService; |
||
21 | |||
22 | function __construct() |
||
28 | |||
29 | /** |
||
30 | * |
||
31 | * Removes URLs from strings |
||
32 | * |
||
33 | * @param array|string $data |
||
34 | * @return array|string|string[]|null |
||
35 | */ |
||
36 | public function removeUrl($data) |
||
60 | |||
61 | /** |
||
62 | * @param $data |
||
63 | * @param string $toEncoding |
||
64 | * @param string $fromEncoding |
||
65 | * @return array|false|string|string[]|null |
||
66 | */ |
||
67 | public function cleanse($data, $toEncoding = 'utf-8', $fromEncoding = 'auto') |
||
88 | |||
89 | /** |
||
90 | * @param $string |
||
91 | * @param string $delimiter |
||
92 | * @return string |
||
93 | */ |
||
94 | public function cleanseCsv($string, $delimiter = "|") |
||
98 | |||
99 | /** |
||
100 | * @param $data |
||
101 | * @param string $type |
||
102 | * @param int $stringLength |
||
103 | * @return mixed|string |
||
104 | */ |
||
105 | 4 | public function disinfect($data, $type = 'special_chars', $stringLength = -1) |
|
106 | { |
||
107 | |||
108 | 4 | $this->_sanitised = null; |
|
109 | |||
110 | 4 | if (is_array($data)) { |
|
111 | foreach ($data as $key => $value) { |
||
112 | $data[$key] = $this->disinfect($value, $type, $stringLength); |
||
113 | } |
||
114 | return $data; |
||
115 | } |
||
116 | |||
117 | 4 | $this->input = $data = trim($data); |
|
118 | |||
119 | 4 | $data = $this->strings->clean($data); |
|
120 | 4 | $data = $this->strings->stringLength($data, $stringLength); |
|
121 | |||
122 | 4 | switch ($type) { |
|
123 | 4 | case "email": |
|
124 | $filterResult = $this->filters->filterEmail($data); |
||
125 | break; |
||
126 | |||
127 | 4 | case "encoded": |
|
128 | $filterResult = $this->filters->filterEncoded($data); |
||
129 | break; |
||
130 | |||
131 | 4 | case "number_float": |
|
132 | 4 | case "float": |
|
133 | $filterResult = $this->filters->filterFloat($data); |
||
134 | break; |
||
135 | |||
136 | 4 | case "number_int": |
|
137 | 4 | case "int": |
|
138 | $filterResult = $this->filters->filterInt($data); |
||
139 | break; |
||
140 | |||
141 | 4 | case "full_special_chars": |
|
142 | $filterResult = $this->filters->filterFullSpecialChar($data); |
||
143 | break; |
||
144 | |||
145 | 4 | case "url": |
|
146 | $filterResult = $this->filters->filterUrl($data); |
||
147 | break; |
||
148 | |||
149 | 4 | case "string": |
|
150 | 3 | $filterResult = $this->filters->filterString($data); |
|
151 | 3 | break; |
|
152 | |||
153 | default: |
||
154 | 1 | case "special_chars": |
|
155 | 1 | $filterResult = $this->filters->filterSpecial($data); |
|
156 | 1 | break; |
|
157 | } |
||
158 | |||
159 | 4 | if ($this->input != $filterResult->getResult()) { |
|
160 | 3 | $this->_sanitised = true; |
|
161 | } |
||
162 | |||
163 | 4 | $this->is_valid = $filterResult->isValid(); |
|
164 | 4 | $this->output = $filterResult->getResult(); |
|
165 | 4 | return $this->output; |
|
166 | } |
||
167 | |||
168 | |||
169 | /** |
||
170 | * @return null |
||
171 | */ |
||
172 | public function isSanitised() |
||
176 | |||
177 | /** |
||
178 | * Returns true if the data is valid |
||
179 | * @return null |
||
180 | */ |
||
181 | public function isValid() |
||
185 | |||
186 | 4 | function result() |
|
194 | |||
195 | } |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.