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_setautoloadfilters.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Smarty Method SetAutoloadFilters
  4. *
  5. * Smarty::setAutoloadFilters() method
  6. *
  7. * @package Smarty
  8. * @subpackage PluginsInternal
  9. * @author Uwe Tews
  10. */
  11. class Smarty_Internal_Method_SetAutoloadFilters
  12. {
  13. /**
  14. * Valid for Smarty and template object
  15. *
  16. * @var int
  17. */
  18. public $objMap = 3;
  19. /**
  20. * Valid filter types
  21. *
  22. * @var array
  23. */
  24. private $filterTypes = array('pre' => true, 'post' => true, 'output' => true, 'variable' => true);
  25. /**
  26. * Set autoload filters
  27. *
  28. * @api Smarty::setAutoloadFilters()
  29. *
  30. * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
  31. * @param array $filters filters to load automatically
  32. * @param string $type "pre", "output", … specify the
  33. * filter type to set. Defaults to
  34. * none treating $filters' keys as
  35. * the appropriate types
  36. *
  37. * @return \Smarty|\Smarty_Internal_Template
  38. */
  39. public function setAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null)
  40. {
  41. $smarty = isset($obj->smarty) ? $obj->smarty : $obj;
  42. if ($type !== null) {
  43. $this->_checkFilterType($type);
  44. $smarty->autoload_filters[$type] = (array) $filters;
  45. } else {
  46. foreach ((array) $filters as $type => $value) {
  47. $this->_checkFilterType($type);
  48. }
  49. $smarty->autoload_filters = (array) $filters;
  50. }
  51. return $obj;
  52. }
  53. /**
  54. * Check if filter type is valid
  55. *
  56. * @param string $type
  57. *
  58. * @throws \SmartyException
  59. */
  60. public function _checkFilterType($type)
  61. {
  62. if (!isset($this->filterTypes[$type])) {
  63. throw new SmartyException("Illegal filter type \"{$type}\"");
  64. }
  65. }
  66. }