4 * Smarty Method RegisterPlugin
6 * Smarty::registerPlugin() method
9 * @subpackage PluginsInternal
12 class Smarty_Internal_Method_RegisterPlugin
15 * Valid for Smarty and template object
22 * Registers plugin to be used in templates
24 * @api Smarty::registerPlugin()
25 * @link http://www.smarty.net/docs/en/api.register.plugin.tpl
27 * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
28 * @param string $type plugin type
29 * @param string $name name of template tag
30 * @param callback $callback PHP callback to register
31 * @param bool $cacheable if true (default) this
32 * function is cache able
33 * @param mixed $cache_attr caching attributes if any
35 * @return \Smarty|\Smarty_Internal_Template
36 * @throws SmartyException when the plugin tag is invalid
38 public function registerPlugin(Smarty_Internal_TemplateBase $obj, $type, $name, $callback, $cacheable = true,
41 $smarty = $obj->_getSmartyObj();
42 if (isset($smarty->registered_plugins[ $type ][ $name ])) {
43 throw new SmartyException("Plugin tag \"{$name}\" already registered");
44 } elseif (!is_callable($callback)) {
45 throw new SmartyException("Plugin \"{$name}\" not callable");
47 $smarty->registered_plugins[ $type ][ $name ] = array($callback, (bool) $cacheable, (array) $cache_attr);