Subversion Repositories ALCASAR

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
2809 rexy 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
     * Add autoload filters
16
     *
17
     * @api Smarty::setAutoloadFilters()
18
     *
19
     * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
20
     * @param array                                                           $filters filters to load automatically
21
     * @param string                                                          $type    "pre", "output", … specify
22
     *                                                                                 the filter type to set.
23
     *                                                                                 Defaults to none treating
24
     *                                                                                 $filters' keys as the
25
     *                                                                                 appropriate types
26
     *
27
     * @return \Smarty|\Smarty_Internal_Template
28
     * @throws \SmartyException
29
     */
30
    public function addAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null)
31
    {
32
        $smarty = $obj->_getSmartyObj();
33
        if ($type !== null) {
34
            $this->_checkFilterType($type);
35
            if (!empty($smarty->autoload_filters[ $type ])) {
36
                $smarty->autoload_filters[ $type ] = array_merge($smarty->autoload_filters[ $type ], (array)$filters);
37
            } else {
38
                $smarty->autoload_filters[ $type ] = (array)$filters;
39
            }
40
        } else {
41
            foreach ((array)$filters as $type => $value) {
42
                $this->_checkFilterType($type);
43
                if (!empty($smarty->autoload_filters[ $type ])) {
44
                    $smarty->autoload_filters[ $type ] =
45
                        array_merge($smarty->autoload_filters[ $type ], (array)$value);
46
                } else {
47
                    $smarty->autoload_filters[ $type ] = (array)$value;
48
                }
49
            }
50
        }
51
        return $obj;
52
    }
53
}