You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smarty_internal_method_registerplugin.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Smarty Method RegisterPlugin
  4. *
  5. * Smarty::registerPlugin() method
  6. *
  7. * @package Smarty
  8. * @subpackage PluginsInternal
  9. * @author Uwe Tews
  10. */
  11. class Smarty_Internal_Method_RegisterPlugin
  12. {
  13. /**
  14. * Valid for Smarty and template object
  15. *
  16. * @var int
  17. */
  18. public $objMap = 3;
  19. /**
  20. * Registers plugin to be used in templates
  21. *
  22. * @api Smarty::registerPlugin()
  23. * @link http://www.smarty.net/docs/en/api.register.plugin.tpl
  24. *
  25. * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
  26. * @param string $type plugin type
  27. * @param string $name name of template tag
  28. * @param callback $callback PHP callback to register
  29. * @param bool $cacheable if true (default) this
  30. * function is cache able
  31. * @param mixed $cache_attr caching attributes if any
  32. *
  33. * @return \Smarty|\Smarty_Internal_Template
  34. * @throws SmartyException when the plugin tag is invalid
  35. */
  36. public function registerPlugin(Smarty_Internal_TemplateBase $obj, $type, $name, $callback, $cacheable = true, $cache_attr = null)
  37. {
  38. $smarty = isset($obj->smarty) ? $obj->smarty : $obj;
  39. if (isset($smarty->registered_plugins[$type][$name])) {
  40. throw new SmartyException("Plugin tag \"{$name}\" already registered");
  41. } elseif (!is_callable($callback)) {
  42. throw new SmartyException("Plugin \"{$name}\" not callable");
  43. } else {
  44. $smarty->registered_plugins[$type][$name] = array($callback, (bool) $cacheable, (array) $cache_attr);
  45. }
  46. return $obj;
  47. }
  48. }