Array.php 962B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. class Twig_Node_Expression_Array extends Twig_Node_Expression
  11. {
  12. public function __construct(array $elements, $lineno)
  13. {
  14. parent::__construct($elements, array(), $lineno);
  15. }
  16. /**
  17. * Compiles the node to PHP.
  18. *
  19. * @param Twig_Compiler A Twig_Compiler instance
  20. */
  21. public function compile(Twig_Compiler $compiler)
  22. {
  23. $compiler->raw('array(');
  24. $first = true;
  25. foreach ($this->nodes as $name => $node) {
  26. if (!$first) {
  27. $compiler->raw(', ');
  28. }
  29. $first = false;
  30. $compiler
  31. ->repr($name)
  32. ->raw(' => ')
  33. ->subcompile($node)
  34. ;
  35. }
  36. $compiler->raw(')');
  37. }
  38. }