4 * Smarty Method LoadFilter
6 * Smarty::loadFilter() method
9 * @subpackage PluginsInternal
12 class Smarty_Internal_Method_LoadFilter
15 * Valid for Smarty and template object
26 private $filterTypes = array('pre' => true, 'post' => true, 'output' => true, 'variable' => true);
29 * load a filter of specified type and name
31 * @api Smarty::loadFilter()
33 * @link http://www.smarty.net/docs/en/api.load.filter.tpl
35 * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
36 * @param string $type filter type
37 * @param string $name filter name
40 * @throws SmartyException if filter could not be loaded
42 public function loadFilter(Smarty_Internal_TemplateBase $obj, $type, $name)
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;
52 if ($smarty->loadPlugin($_plugin)) {
53 if (class_exists($_plugin, false)) {
54 $_plugin = array($_plugin, 'execute');
56 if (is_callable($_plugin)) {
57 $smarty->registered_filters[ $type ][ $_filter_name ] = $_plugin;
61 throw new SmartyException("{$type}filter \"{$name}\" not found or callable");
65 * Check if filter type is valid
69 * @throws \SmartyException
71 public function _checkFilterType($type)
73 if (!isset($this->filterTypes[ $type ])) {
74 throw new SmartyException("Illegal filter type \"{$type}\"");