1- <?php
2- /** Red Framework
3- * Filter Class
4- * @author RedCoder
5- * http://redframework.ir
6- */
7-
8- namespace Red \SanitizeService ;
9-
10-
11- class Sanitize
12- {
13-
14- private static $ roles = array ();
15-
16- public static function initialize (){
17- Rules::rules ();
18- }
19-
20- public static function sanitize ($ string , $ method )
21- {
22- if ($ method == 'digit ' ) {
23- return preg_replace ('/([0-9])+/ ' , '' , $ string );
24- } else if ($ method == 'space ' ) {
25- $ string = preg_replace ('/([\s\n])+/ ' , '' , $ string );
26- return $ string ;
27- }
28-
29- foreach (self ::$ roles as $ role ){
30- if ($ role [ ' role ' ] == $ method ){
31- $ result = call_user_func_array ($ role ['callback ' ], [$ string ]);
32- return $ result ;
33- }
34- }
35-
36- return FALSE ;
37- }
38-
39- /**
40- * @param string $role
41- * @param callable $callback
42- * @return bool
43- */
44- public static function addRole ($ role , $ callback )
45- {
46-
47- array_push (self ::$ roles , ['role ' => $ role , 'callback ' => $ callback ]);
48- return TRUE ;
49- }
50-
51- /**
52- * @return mixed
53- */
54- public static function getRoles ()
55- {
56- return self ::$ roles ;
57- }
58-
59-
1+ <?php
2+ /** Red Framework
3+ * Filter Class
4+ * @author RedCoder
5+ * http://redframework.ir
6+ */
7+
8+ namespace Red \SanitizeService ;
9+
10+
11+ class Sanitize
12+ {
13+
14+ private static $ rules = array ();
15+
16+ public static function initialize (){
17+ Rules::rules ();
18+ }
19+
20+ public static function sanitize ($ string , $ method )
21+ {
22+ if ($ method == 'digit ' ) {
23+ return preg_replace ('/([0-9])+/ ' , '' , $ string );
24+ } else if ($ method == 'space ' ) {
25+ $ string = preg_replace ('/([\s\n])+/ ' , '' , $ string );
26+ return $ string ;
27+ }
28+
29+ foreach (self ::$ rules as $ rule ){
30+ if ($ rule [ ' rule ' ] == $ method ){
31+ $ result = call_user_func_array ($ rule ['callback ' ], [$ string ]);
32+ return $ result ;
33+ }
34+ }
35+
36+ return FALSE ;
37+ }
38+
39+ /**
40+ * @param string $role
41+ * @param callable $callback
42+ * @return bool
43+ */
44+ public static function addRole ($ rule , $ callback )
45+ {
46+
47+ array_push (self ::$ rules , ['rule ' => $ rule , 'callback ' => $ callback ]);
48+ return TRUE ;
49+ }
50+
51+ /**
52+ * @return mixed
53+ */
54+ public static function getRules ()
55+ {
56+ return self ::$ rules ;
57+ }
58+
59+
6060}
0 commit comments