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.

SimpleTokenParser.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_Node) {
  33. if ($value instanceof Twig_Node_Expression_Array) {
  34. $nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Function('dump', $value, $line), $line);
  35. } else {
  36. $nodes[] = new Twig_Node_Print($value, $line);
  37. }
  38. } else {
  39. $nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Constant($value, $line), $line);
  40. }
  41. $nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Constant('|', $line), $line);
  42. }
  43. return new Twig_Node($nodes);
  44. }
  45. }