1: <?php
2:
3: /**
4: * Jyxo PHP Library
5: *
6: * LICENSE
7: *
8: * This source file is subject to the new BSD license that is bundled
9: * with this package in the file license.txt.
10: * It is also available through the world-wide-web at this URL:
11: * https://github.com/jyxo/php/blob/master/license.txt
12: */
13:
14: /**
15: * Parent class of all filters.
16: * Allows multidimensional arrays filtering.
17: *
18: * @category Jyxo
19: * @package Jyxo_Input
20: * @subpackage Filter
21: * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
22: * @license https://github.com/jyxo/php/blob/master/license.txt
23: * @author Jaroslav HanslĂk
24: */
25: abstract class Jyxo_Input_Filter_AbstractFilter implements Jyxo_Input_FilterInterface
26: {
27: /**
28: * Creates a filter instance.
29: */
30: public function __construct()
31: {}
32:
33: /**
34: * Filters a value.
35: *
36: * @param mixed $value Input value
37: * @return mixed
38: */
39: public static function filtrate($value)
40: {
41: $filter = new static();
42: return $filter->filter($value);
43: }
44:
45: /**
46: * Actually filters a value.
47: *
48: * @param mixed $in Input value
49: * @return mixed
50: */
51: abstract protected function filterValue($in);
52:
53: /**
54: * Filters a value.
55: *
56: * @param mixed $in Object to be filtered
57: * @return Jyxo_Input_FilterInterface This object instance
58: */
59: public function filter($in)
60: {
61: if (is_array($in)) {
62: return array_map(array($this, 'filter'), $in);
63: }
64: return $this->filterValue($in);
65: }
66: }
67: