]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_loadfilter.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_method_loadfilter.php
1 <?php
2
3 /**
4  * Smarty Method LoadFilter
5  *
6  * Smarty::loadFilter() method
7  *
8  * @package    Smarty
9  * @subpackage PluginsInternal
10  * @author     Uwe Tews
11  */
12 class Smarty_Internal_Method_LoadFilter
13 {
14     /**
15      * Valid for Smarty and template object
16      *
17      * @var int
18      */
19     public $objMap = 3;
20
21     /**
22      * Valid filter types
23      *
24      * @var array
25      */
26     private $filterTypes = array('pre' => true, 'post' => true, 'output' => true, 'variable' => true);
27
28     /**
29      * load a filter of specified type and name
30      *
31      * @api  Smarty::loadFilter()
32      *
33      * @link http://www.smarty.net/docs/en/api.load.filter.tpl
34      *
35      * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
36      * @param  string                                                         $type filter type
37      * @param  string                                                         $name filter name
38      *
39      * @return bool
40      * @throws SmartyException if filter could not be loaded
41      */
42     public function loadFilter(Smarty_Internal_TemplateBase $obj, $type, $name)
43     {
44         $smarty = $obj->_getSmartyObj();
45         $this->_checkFilterType($type);
46         $_plugin = "smarty_{$type}filter_{$name}";
47         $_filter_name = $_plugin;
48         if (is_callable($_plugin)) {
49             $smarty->registered_filters[ $type ][ $_filter_name ] = $_plugin;
50             return true;
51         }
52         if ($smarty->loadPlugin($_plugin)) {
53             if (class_exists($_plugin, false)) {
54                 $_plugin = array($_plugin, 'execute');
55             }
56             if (is_callable($_plugin)) {
57                 $smarty->registered_filters[ $type ][ $_filter_name ] = $_plugin;
58                 return true;
59             }
60         }
61         throw new SmartyException("{$type}filter \"{$name}\" not found or callable");
62     }
63
64     /**
65      * Check if filter type is valid
66      *
67      * @param string $type
68      *
69      * @throws \SmartyException
70      */
71     public function _checkFilterType($type)
72     {
73         if (!isset($this->filterTypes[ $type ])) {
74             throw new SmartyException("Illegal filter type \"{$type}\"");
75         }
76     }
77 }