HelperTokenParser.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Symfony\Bundle\TwigBundle\TokenParser;
  3. use Symfony\Bundle\TwigBundle\Node\HelperNode;
  4. /*
  5. * This file is part of the Symfony package.
  6. *
  7. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  8. *
  9. * For the full copyright and license information, please view the LICENSE
  10. * file that was distributed with this source code.
  11. */
  12. /**
  13. * Wrapper for Symfony helpers.
  14. *
  15. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  16. */
  17. class HelperTokenParser extends \Twig_SimpleTokenParser
  18. {
  19. protected $helper;
  20. protected $method;
  21. protected $grammar;
  22. protected $tag;
  23. public function __construct($tag = null, $grammar = null, $helper = null, $method = null)
  24. {
  25. $this->tag = $tag;
  26. $this->grammar = $grammar;
  27. $this->helper = $helper;
  28. $this->method = $method;
  29. }
  30. /**
  31. * Gets the tag name associated with this token parser.
  32. *
  33. * @return string The tag name
  34. */
  35. public function getTag()
  36. {
  37. return $this->tag;
  38. }
  39. /**
  40. * Gets the grammar as an object or as a string.
  41. *
  42. * @return string|Twig_Grammar A Twig_Grammar instance or a string
  43. */
  44. protected function getGrammar()
  45. {
  46. return $this->grammar;
  47. }
  48. protected function getNode(array $values, $line)
  49. {
  50. return $this->output(
  51. $this->markAsSafe(
  52. new HelperNode($this->helper, $this->method, new \Twig_Node_Expression_Array($this->getNodeValues($values), $line), $line)
  53. ));
  54. }
  55. }