[ Index ]

PHP Cross Reference of phpBB-3.3.12-deutsch

title

Body

[close]

/vendor/twig/twig/src/Node/ -> IfNode.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of Twig.
   5   *
   6   * (c) Fabien Potencier
   7   * (c) Armin Ronacher
   8   *
   9   * For the full copyright and license information, please view the LICENSE
  10   * file that was distributed with this source code.
  11   */
  12  
  13  namespace Twig\Node;
  14  
  15  use Twig\Compiler;
  16  
  17  /**
  18   * Represents an if node.
  19   *
  20   * @author Fabien Potencier <fabien@symfony.com>
  21   */
  22  class IfNode extends Node
  23  {
  24      public function __construct(Node $tests, ?Node $else, int $lineno, string $tag = null)
  25      {
  26          $nodes = ['tests' => $tests];
  27          if (null !== $else) {
  28              $nodes['else'] = $else;
  29          }
  30  
  31          parent::__construct($nodes, [], $lineno, $tag);
  32      }
  33  
  34      public function compile(Compiler $compiler)
  35      {
  36          $compiler->addDebugInfo($this);
  37          for ($i = 0, $count = \count($this->getNode('tests')); $i < $count; $i += 2) {
  38              if ($i > 0) {
  39                  $compiler
  40                      ->outdent()
  41                      ->write('} elseif (')
  42                  ;
  43              } else {
  44                  $compiler
  45                      ->write('if (')
  46                  ;
  47              }
  48  
  49              $compiler
  50                  ->subcompile($this->getNode('tests')->getNode($i))
  51                  ->raw(") {\n")
  52                  ->indent()
  53              ;
  54              // The node might not exists if the content is empty
  55              if ($this->getNode('tests')->hasNode($i + 1)) {
  56                  $compiler->subcompile($this->getNode('tests')->getNode($i + 1));
  57              }
  58          }
  59  
  60          if ($this->hasNode('else')) {
  61              $compiler
  62                  ->outdent()
  63                  ->write("} else {\n")
  64                  ->indent()
  65                  ->subcompile($this->getNode('else'))
  66              ;
  67          }
  68  
  69          $compiler
  70              ->outdent()
  71              ->write("}\n");
  72      }
  73  }
  74  
  75  class_alias('Twig\Node\IfNode', 'Twig_Node_If');


Generated: Sun Jun 23 12:25:44 2024 Cross-referenced by PHPXref 0.7.1