]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_addautoloadfilters.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_method_addautoloadfilters.php
1 <?php
2
3 /**
4  * Smarty Method AddAutoloadFilters
5  *
6  * Smarty::addAutoloadFilters() method
7  *
8  * @package    Smarty
9  * @subpackage PluginsInternal
10  * @author     Uwe Tews
11  */
12 class Smarty_Internal_Method_AddAutoloadFilters extends Smarty_Internal_Method_SetAutoloadFilters
13 {
14
15     /**
16      * Add autoload filters
17      *
18      * @api Smarty::setAutoloadFilters()
19      *
20      * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
21      * @param  array                                                          $filters filters to load automatically
22      * @param  string                                                         $type    "pre", "output", … specify the
23      *                                                                                 filter type to set. Defaults to
24      *                                                                                 none treating $filters' keys as
25      *                                                                                 the appropriate types
26      *
27      * @return \Smarty|\Smarty_Internal_Template
28      */
29     public function addAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null)
30     {
31         $smarty = $obj->_getSmartyObj();
32         if ($type !== null) {
33             $this->_checkFilterType($type);
34             if (!empty($smarty->autoload_filters[ $type ])) {
35                 $smarty->autoload_filters[ $type ] = array_merge($smarty->autoload_filters[ $type ], (array) $filters);
36             } else {
37                 $smarty->autoload_filters[ $type ] = (array) $filters;
38             }
39         } else {
40             foreach ((array) $filters as $type => $value) {
41                 $this->_checkFilterType($type);
42                 if (!empty($smarty->autoload_filters[ $type ])) {
43                     $smarty->autoload_filters[ $type ] =
44                         array_merge($smarty->autoload_filters[ $type ], (array) $value);
45                 } else {
46                     $smarty->autoload_filters[ $type ] = (array) $value;
47                 }
48             }
49         }
50         return $obj;
51     }
52 }