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_addautoloadfilters.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Smarty Method AddAutoloadFilters
  4. *
  5. * Smarty::addAutoloadFilters() method
  6. *
  7. * @package Smarty
  8. * @subpackage PluginsInternal
  9. * @author Uwe Tews
  10. */
  11. class Smarty_Internal_Method_AddAutoloadFilters extends Smarty_Internal_Method_SetAutoloadFilters
  12. {
  13. /**
  14. * Add autoload filters
  15. *
  16. * @api Smarty::setAutoloadFilters()
  17. *
  18. * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
  19. * @param array $filters filters to load automatically
  20. * @param string $type "pre", "output", … specify the
  21. * filter type to set. Defaults to
  22. * none treating $filters' keys as
  23. * the appropriate types
  24. *
  25. * @return \Smarty|\Smarty_Internal_Template
  26. */
  27. public function addAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null)
  28. {
  29. $smarty = isset($obj->smarty) ? $obj->smarty : $obj;
  30. if ($type !== null) {
  31. $this->_checkFilterType($type);
  32. if (!empty($smarty->autoload_filters[$type])) {
  33. $smarty->autoload_filters[$type] = array_merge($smarty->autoload_filters[$type], (array) $filters);
  34. } else {
  35. $smarty->autoload_filters[$type] = (array) $filters;
  36. }
  37. } else {
  38. foreach ((array) $filters as $type => $value) {
  39. $this->_checkFilterType($type);
  40. if (!empty($smarty->autoload_filters[$type])) {
  41. $smarty->autoload_filters[$type] = array_merge($smarty->autoload_filters[$type], (array) $value);
  42. } else {
  43. $smarty->autoload_filters[$type] = (array) $value;
  44. }
  45. }
  46. }
  47. return $obj;
  48. }
  49. }