]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_setautoloadfilters.php
Merge pull request #4232 from fabrixxm/frio-login
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_method_setautoloadfilters.php
1 <?php
2
3 /**
4  * Smarty Method SetAutoloadFilters
5  *
6  * Smarty::setAutoloadFilters() method
7  *
8  * @package    Smarty
9  * @subpackage PluginsInternal
10  * @author     Uwe Tews
11  */
12 class Smarty_Internal_Method_SetAutoloadFilters
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      * Set autoload filters
30      *
31      * @api Smarty::setAutoloadFilters()
32      *
33      * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
34      * @param  array                                                          $filters filters to load automatically
35      * @param  string                                                         $type    "pre", "output", … specify the
36      *                                                                                 filter type to set. Defaults to
37      *                                                                                 none treating $filters' keys as
38      *                                                                                 the appropriate types
39      *
40      * @return \Smarty|\Smarty_Internal_Template
41      */
42     public function setAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null)
43     {
44         $smarty = $obj->_getSmartyObj();
45         if ($type !== null) {
46             $this->_checkFilterType($type);
47             $smarty->autoload_filters[ $type ] = (array) $filters;
48         } else {
49             foreach ((array) $filters as $type => $value) {
50                 $this->_checkFilterType($type);
51             }
52             $smarty->autoload_filters = (array) $filters;
53         }
54         return $obj;
55     }
56
57     /**
58      * Check if filter type is valid
59      *
60      * @param string $type
61      *
62      * @throws \SmartyException
63      */
64     public function _checkFilterType($type)
65     {
66         if (!isset($this->filterTypes[ $type ])) {
67             throw new SmartyException("Illegal filter type \"{$type}\"");
68         }
69     }
70 }