Filter.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2009 Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. @trigger_error('The Twig_Filter class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFilter instead.', E_USER_DEPRECATED);
  11. /**
  12. * Represents a template filter.
  13. *
  14. * Use Twig_SimpleFilter instead.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. *
  18. * @deprecated since 1.12 (to be removed in 2.0)
  19. */
  20. abstract class Twig_Filter implements Twig_FilterInterface, Twig_FilterCallableInterface
  21. {
  22. protected $options;
  23. protected $arguments = array();
  24. public function __construct(array $options = array())
  25. {
  26. $this->options = array_merge(array(
  27. 'needs_environment' => false,
  28. 'needs_context' => false,
  29. 'pre_escape' => null,
  30. 'preserves_safety' => null,
  31. 'callable' => null,
  32. ), $options);
  33. }
  34. public function setArguments($arguments)
  35. {
  36. $this->arguments = $arguments;
  37. }
  38. public function getArguments()
  39. {
  40. return $this->arguments;
  41. }
  42. public function needsEnvironment()
  43. {
  44. return $this->options['needs_environment'];
  45. }
  46. public function needsContext()
  47. {
  48. return $this->options['needs_context'];
  49. }
  50. public function getSafe(Twig_Node $filterArgs)
  51. {
  52. if (isset($this->options['is_safe'])) {
  53. return $this->options['is_safe'];
  54. }
  55. if (isset($this->options['is_safe_callback'])) {
  56. return call_user_func($this->options['is_safe_callback'], $filterArgs);
  57. }
  58. }
  59. public function getPreservesSafety()
  60. {
  61. return $this->options['preserves_safety'];
  62. }
  63. public function getPreEscape()
  64. {
  65. return $this->options['pre_escape'];
  66. }
  67. public function getCallable()
  68. {
  69. return $this->options['callable'];
  70. }
  71. }