SimpleTokenParser.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 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. class SimpleTokenParser extends Twig_Extensions_SimpleTokenParser
  11. {
  12. protected $tag;
  13. protected $grammar;
  14. public function __construct($tag, $grammar)
  15. {
  16. $this->tag = $tag;
  17. $this->grammar = $grammar;
  18. }
  19. public function getGrammar()
  20. {
  21. return $this->grammar;
  22. }
  23. public function getTag()
  24. {
  25. return $this->tag;
  26. }
  27. public function getNode(array $values, $line)
  28. {
  29. $nodes = array();
  30. $nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Constant('|', $line), $line);
  31. foreach ($values as $value) {
  32. if ($value instanceof Twig_NodeInterface) {
  33. $nodes[] = new Twig_Node_Print($value, $line);
  34. } else {
  35. $nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Constant($value, $line), $line);
  36. }
  37. $nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Constant('|', $line), $line);
  38. }
  39. return new Twig_Node($nodes);
  40. }
  41. }