1<?php
2
3/**
4 * Smarty Method UnregisterFilter
5 *
6 * Smarty::unregisterFilter() method
7 *
8 * @package    Smarty
9 * @subpackage PluginsInternal
10 * @author     Uwe Tews
11 */
12class Smarty_Internal_Method_UnregisterFilter extends Smarty_Internal_Method_RegisterFilter
13{
14    /**
15     * Unregisters a filter function
16     *
17     * @api  Smarty::unregisterFilter()
18     *
19     * @link http://www.smarty.net/docs/en/api.unregister.filter.tpl
20     *
21     * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
22     * @param string                                                          $type filter type
23     * @param callback|string                                                 $callback
24     *
25     * @return \Smarty|\Smarty_Internal_Template
26     * @throws \SmartyException
27     */
28    public function unregisterFilter(Smarty_Internal_TemplateBase $obj, $type, $callback)
29    {
30        $smarty = $obj->_getSmartyObj();
31        $this->_checkFilterType($type);
32        if (isset($smarty->registered_filters[ $type ])) {
33            $name = is_string($callback) ? $callback : $this->_getFilterName($callback);
34            if (isset($smarty->registered_filters[ $type ][ $name ])) {
35                unset($smarty->registered_filters[ $type ][ $name ]);
36                if (empty($smarty->registered_filters[ $type ])) {
37                    unset($smarty->registered_filters[ $type ]);
38                }
39            }
40        }
41        return $obj;
42    }
43}
44