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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * @throws \SmartyException
  39. */
  40. public function setAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null)
  41. {
  42. $smarty = $obj->_getSmartyObj();
  43. if ($type !== null) {
  44. $this->_checkFilterType($type);
  45. $smarty->autoload_filters[ $type ] = (array) $filters;
  46. } else {
  47. foreach ((array) $filters as $type => $value) {
  48. $this->_checkFilterType($type);
  49. }
  50. $smarty->autoload_filters = (array) $filters;
  51. }
  52. return $obj;
  53. }
  54. /**
  55. * Check if filter type is valid
  56. *
  57. * @param string $type
  58. *
  59. * @throws \SmartyException
  60. */
  61. public function _checkFilterType($type)
  62. {
  63. if (!isset($this->filterTypes[ $type ])) {
  64. throw new SmartyException("Illegal filter type '{$type}'");
  65. }
  66. }
  67. }