Implement hoplite\filter\RawString
[hoplite.git] / base / filter.php
1 <?php
2 // Hoplite
3 // Copyright (c) 2011 Blue Static
4 //
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General License as published by the Free
7 // Software Foundation, either version 3 of the License, or any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General License for
12 // more details.
13 //
14 // You should have received a copy of the GNU General License along with
15 // this program. If not, see <http://www.gnu.org/licenses/>.
16
17 namespace hoplite\base\filter;
18
19 function TrimmedString($str)
20 {
21 return trim($str);
22 }
23
24 function String($str)
25 {
26 $find = array(
27 '<',
28 '>',
29 '"'
30 );
31 $replace = array(
32 '&lt;',
33 '&gt;',
34 '&quot;'
35 );
36 return str_replace($find, $replace, $str);
37 }
38
39 function RawString($str)
40 {
41 return $str;
42 }
43
44 function Int($int)
45 {
46 return intval($int);
47 }
48
49 function Float($float)
50 {
51 return floatval($float);
52 }
53
54 function Bool($bool)
55 {
56 $str = strtolower(TrimmedString($bool));
57 if ($str == 'yes' || $str == 'true')
58 return TRUE;
59 else if ($str == 'no' || $str == 'false')
60 return FALSE;
61 return (bool)$bool;
62 }