Twig_Node_Set

Represents a set node.

Defined (1)

The class is defined in the following location(s).

/vendor/twig/twig/lib/Twig/Node/Set.php  
  1. class Twig_Node_Set extends Twig_Node implements Twig_NodeCaptureInterface 
  2. public function __construct($capture, Twig_NodeInterface $names, Twig_NodeInterface $values, $lineno, $tag = null) 
  3. parent::__construct(array('names' => $names, 'values' => $values), array('capture' => $capture, 'safe' => false), $lineno, $tag); 
  4.  
  5. /** 
  6. * Optimizes the node when capture is used for a large block of text. 
  7. * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig_Markup("foo"); 
  8. */ 
  9. if ($this->getAttribute('capture')) { 
  10. $this->setAttribute('safe', true); 
  11.  
  12. $values = $this->getNode('values'); 
  13. if ($values instanceof Twig_Node_Text) { 
  14. $this->setNode('values', new Twig_Node_Expression_Constant($values->getAttribute('data'), $values->getTemplateLine())); 
  15. $this->setAttribute('capture', false); 
  16.  
  17. public function compile(Twig_Compiler $compiler) 
  18. $compiler->addDebugInfo($this); 
  19.  
  20. if (count($this->getNode('names')) > 1) { 
  21. $compiler->write('list('); 
  22. foreach ($this->getNode('names') as $idx => $node) { 
  23. if ($idx) { 
  24. $compiler->raw(', '); 
  25.  
  26. $compiler->subcompile($node); 
  27. $compiler->raw(')'); 
  28. } else { 
  29. if ($this->getAttribute('capture')) { 
  30. $compiler 
  31. ->write("ob_start();\n") 
  32. ->subcompile($this->getNode('values')) 
  33.  
  34. $compiler->subcompile($this->getNode('names'), false); 
  35.  
  36. if ($this->getAttribute('capture')) { 
  37. $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())"); 
  38.  
  39. if (!$this->getAttribute('capture')) { 
  40. $compiler->raw(' = '); 
  41.  
  42. if (count($this->getNode('names')) > 1) { 
  43. $compiler->write('array('); 
  44. foreach ($this->getNode('values') as $idx => $value) { 
  45. if ($idx) { 
  46. $compiler->raw(', '); 
  47.  
  48. $compiler->subcompile($value); 
  49. $compiler->raw(')'); 
  50. } else { 
  51. if ($this->getAttribute('safe')) { 
  52. $compiler 
  53. ->raw("('' === \$tmp = ") 
  54. ->subcompile($this->getNode('values')) 
  55. ->raw(") ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())") 
  56. } else { 
  57. $compiler->subcompile($this->getNode('values')); 
  58.  
  59. $compiler->raw(";\n");