Function.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2010 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_Function class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFunction instead.', E_USER_DEPRECATED);
  11. /**
  12. * Represents a template function.
  13. *
  14. * Use Twig_SimpleFunction 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_Function implements Twig_FunctionInterface, Twig_FunctionCallableInterface
  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. 'callable' => null,
  30. ), $options);
  31. }
  32. public function setArguments($arguments)
  33. {
  34. $this->arguments = $arguments;
  35. }
  36. public function getArguments()
  37. {
  38. return $this->arguments;
  39. }
  40. public function needsEnvironment()
  41. {
  42. return $this->options['needs_environment'];
  43. }
  44. public function needsContext()
  45. {
  46. return $this->options['needs_context'];
  47. }
  48. public function getSafe(Twig_Node $functionArgs)
  49. {
  50. if (isset($this->options['is_safe'])) {
  51. return $this->options['is_safe'];
  52. }
  53. if (isset($this->options['is_safe_callback'])) {
  54. return call_user_func($this->options['is_safe_callback'], $functionArgs);
  55. }
  56. return array();
  57. }
  58. public function getCallable()
  59. {
  60. return $this->options['callable'];
  61. }
  62. }