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: namespace Jyxo\Input\Filter;
15:
16: /**
17: * Parent class of all filters.
18: * Allows multidimensional arrays filtering.
19: *
20: * @category Jyxo
21: * @package Jyxo\Input
22: * @subpackage Filter
23: * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
24: * @license https://github.com/jyxo/php/blob/master/license.txt
25: * @author Jaroslav HanslĂk
26: */
27: abstract class AbstractFilter implements \Jyxo\Input\FilterInterface
28: {
29: /**
30: * Creates a filter instance.
31: */
32: public function __construct()
33: {}
34:
35: /**
36: * Filters a value.
37: *
38: * @param mixed $value Input value
39: * @return mixed
40: */
41: public static function filtrate($value)
42: {
43: $filter = new static();
44: return $filter->filter($value);
45: }
46:
47: /**
48: * Actually filters a value.
49: *
50: * @param mixed $in Input value
51: * @return mixed
52: */
53: abstract protected function filterValue($in);
54:
55: /**
56: * Filters a value.
57: *
58: * @param mixed $in Object to be filtered
59: * @return \Jyxo\Input\FilterInterface This object instance
60: */
61: public function filter($in)
62: {
63: if (is_array($in)) {
64: return array_map(array($this, 'filter'), $in);
65: }
66: return $this->filterValue($in);
67: }
68: }
69: