vendor/twig/lib/Twig/Node/Set.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of Twig.
       
     5  *
       
     6  * (c) 2010 Fabien Potencier
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    10  */
       
    11 
       
    12 /**
       
    13  * Represents a set node.
       
    14  *
       
    15  * @package    twig
       
    16  * @author     Fabien Potencier <fabien@symfony.com>
       
    17  */
       
    18 class Twig_Node_Set extends Twig_Node
       
    19 {
       
    20     public function __construct($capture, Twig_NodeInterface $names, Twig_NodeInterface $values, $lineno, $tag = null)
       
    21     {
       
    22         parent::__construct(array('names' => $names, 'values' => $values), array('capture' => $capture), $lineno, $tag);
       
    23     }
       
    24 
       
    25     /**
       
    26      * Compiles the node to PHP.
       
    27      *
       
    28      * @param Twig_Compiler A Twig_Compiler instance
       
    29      */
       
    30     public function compile(Twig_Compiler $compiler)
       
    31     {
       
    32         $compiler->addDebugInfo($this);
       
    33 
       
    34         if (count($this->getNode('names')) > 1) {
       
    35             $compiler->write('list(');
       
    36             foreach ($this->getNode('names') as $idx => $node) {
       
    37                 if ($idx) {
       
    38                     $compiler->raw(', ');
       
    39                 }
       
    40 
       
    41                 $compiler->subcompile($node);
       
    42             }
       
    43             $compiler->raw(')');
       
    44         } else {
       
    45             if ($this->getAttribute('capture')) {
       
    46                 $compiler
       
    47                     ->write("ob_start();\n")
       
    48                     ->subcompile($this->getNode('values'))
       
    49                 ;
       
    50             }
       
    51 
       
    52             $compiler->subcompile($this->getNode('names'), false);
       
    53 
       
    54             if ($this->getAttribute('capture')) {
       
    55                 $compiler->raw(" = new Twig_Markup(ob_get_clean())");
       
    56             }
       
    57         }
       
    58 
       
    59         if (!$this->getAttribute('capture')) {
       
    60             $compiler->raw(' = ');
       
    61 
       
    62             if (count($this->getNode('names')) > 1) {
       
    63                 $compiler->write('array(');
       
    64                 foreach ($this->getNode('values') as $idx => $value) {
       
    65                     if ($idx) {
       
    66                         $compiler->raw(', ');
       
    67                     }
       
    68 
       
    69                     $compiler->subcompile($value);
       
    70                 }
       
    71                 $compiler->raw(')');
       
    72             } else {
       
    73                 $compiler->subcompile($this->getNode('values'));
       
    74             }
       
    75         }
       
    76 
       
    77         $compiler->raw(";\n");
       
    78     }
       
    79 }