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: * Class for easier one-line filtering.
16: *
17: * @category Jyxo
18: * @package Jyxo_Input
19: * @subpackage Filter
20: * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
21: * @license https://github.com/jyxo/php/blob/master/license.txt
22: * @author Jakub Tománek
23: */
24: class Jyxo_Input_Filter
25: {
26: /**
27: * Static filtering.
28: *
29: * @param string $method Filter name
30: * @param array $params Parameters; the first value gets filtered, the rest will be used as constructor parameters
31: * @return mixed
32: */
33: public static function __callStatic($method, array $params)
34: {
35: $factory = Jyxo_Spl_ObjectCache::get('Jyxo_Input_Factory') ?: Jyxo_Spl_ObjectCache::set('Jyxo_Input_Factory', new Jyxo_Input_Factory());
36: $value = array_shift($params);
37: $key = 'Jyxo_Input_Filter_' . ucfirst($method) . ($params ? '/' . serialize($params) : '');
38: $filter = Jyxo_Spl_ObjectCache::get($key) ?: Jyxo_Spl_ObjectCache::set($key, $factory->getFilterByName($method, $params));
39: /* @var $filter Jyxo_Input_FilterInterface */
40: return $filter->filter($value);
41: }
42: }
43: