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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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,
  37. $cache_attr = null)
  38. {
  39. $smarty = $obj->_getSmartyObj();
  40. if (isset($smarty->registered_plugins[ $type ][ $name ])) {
  41. throw new SmartyException("Plugin tag '{$name}' already registered");
  42. } elseif (!is_callable($callback)) {
  43. throw new SmartyException("Plugin '{$name}' not callable");
  44. } else {
  45. $smarty->registered_plugins[ $type ][ $name ] = array($callback, (bool) $cacheable, (array) $cache_attr);
  46. }
  47. return $obj;
  48. }
  49. }