]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_registerplugin.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_method_registerplugin.php
1 <?php
2
3 /**
4  * Smarty Method RegisterPlugin
5  *
6  * Smarty::registerPlugin() method
7  *
8  * @package    Smarty
9  * @subpackage PluginsInternal
10  * @author     Uwe Tews
11  */
12 class Smarty_Internal_Method_RegisterPlugin
13 {
14     /**
15      * Valid for Smarty and template object
16      *
17      * @var int
18      */
19     public $objMap = 3;
20
21     /**
22      * Registers plugin to be used in templates
23      *
24      * @api  Smarty::registerPlugin()
25      * @link http://www.smarty.net/docs/en/api.register.plugin.tpl
26      *
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
34      *
35      * @return \Smarty|\Smarty_Internal_Template
36      * @throws SmartyException              when the plugin tag is invalid
37      */
38     public function registerPlugin(Smarty_Internal_TemplateBase $obj, $type, $name, $callback, $cacheable = true,
39                                    $cache_attr = null)
40     {
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");
46         } else {
47             $smarty->registered_plugins[ $type ][ $name ] = array($callback, (bool) $cacheable, (array) $cache_attr);
48         }
49         return $obj;
50     }
51 }