1: | <?php
|
2: |
|
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: |
|
12: | class Smarty_Internal_Method_RegisterFilter
|
13: | {
|
14: | |
15: | |
16: | |
17: | |
18: |
|
19: | public $objMap = 3;
|
20: |
|
21: | |
22: | |
23: | |
24: | |
25: |
|
26: | private $filterTypes = array('pre' => true, 'post' => true, 'output' => true, 'variable' => true);
|
27: |
|
28: | |
29: | |
30: | |
31: | |
32: | |
33: | |
34: | |
35: | |
36: | |
37: | |
38: | |
39: | |
40: | |
41: | |
42: |
|
43: | public function registerFilter(Smarty_Internal_TemplateBase $obj, $type, $callback, $name = null)
|
44: | {
|
45: | $smarty = $obj->_getSmartyObj();
|
46: | $this->_checkFilterType($type);
|
47: | $name = isset($name) ? $name : $this->_getFilterName($callback);
|
48: | if (!is_callable($callback)) {
|
49: | throw new SmartyException("{$type}filter '{$name}' not callable");
|
50: | }
|
51: | $smarty->registered_filters[ $type ][ $name ] = $callback;
|
52: | return $obj;
|
53: | }
|
54: |
|
55: | |
56: | |
57: | |
58: | |
59: | |
60: | |
61: |
|
62: | public function _getFilterName($function_name)
|
63: | {
|
64: | if (is_array($function_name)) {
|
65: | $_class_name = (is_object($function_name[ 0 ]) ? get_class($function_name[ 0 ]) : $function_name[ 0 ]);
|
66: | return $_class_name . '_' . $function_name[ 1 ];
|
67: | } elseif (is_string($function_name)) {
|
68: | return $function_name;
|
69: | } else {
|
70: | return 'closure';
|
71: | }
|
72: | }
|
73: |
|
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: |
|
81: | public function _checkFilterType($type)
|
82: | {
|
83: | if (!isset($this->filterTypes[ $type ])) {
|
84: | throw new SmartyException("Illegal filter type '{$type}'");
|
85: | }
|
86: | }
|
87: | }
|
88: | |