Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ForNode.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 4.21 KiB


001  <?php
002   
003  /*
004   * This file is part of Twig.
005   *
006   * (c) Fabien Potencier
007   * (c) Armin Ronacher
008   *
009   * For the full copyright and license information, please view the LICENSE
010   * file that was distributed with this source code.
011   */
012   
013  namespace Twig\Node;
014   
015  use Twig\Compiler;
016  use Twig\Node\Expression\AbstractExpression;
017  use Twig\Node\Expression\AssignNameExpression;
018   
019  /**
020   * Represents a for node.
021   *
022   * @author Fabien Potencier <fabien@symfony.com>
023   */
024  class ForNode extends Node
025  {
026      private $loop;
027   
028      public function __construct(AssignNameExpression $keyTarget, AssignNameExpression $valueTarget, AbstractExpression $seq, ?AbstractExpression $ifexpr, Node $body, ?Node $else, int $lineno, string $tag = null)
029      {
030          $body = new Node([$body, $this->loop = new ForLoopNode($lineno, $tag)]);
031   
032          if (null !== $ifexpr) {
033              $body = new IfNode(new Node([$ifexpr, $body]), null, $lineno, $tag);
034          }
035   
036          $nodes = ['key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body];
037          if (null !== $else) {
038              $nodes['else'] = $else;
039          }
040   
041          parent::__construct($nodes, ['with_loop' => true, 'ifexpr' => null !== $ifexpr], $lineno, $tag);
042      }
043   
044      public function compile(Compiler $compiler)
045      {
046          $compiler
047              ->addDebugInfo($this)
048              ->write("\$context['_parent'] = \$context;\n")
049              ->write("\$context['_seq'] = twig_ensure_traversable(")
050              ->subcompile($this->getNode('seq'))
051              ->raw(");\n")
052          ;
053   
054          if ($this->hasNode('else')) {
055              $compiler->write("\$context['_iterated'] = false;\n");
056          }
057   
058          if ($this->getAttribute('with_loop')) {
059              $compiler
060                  ->write("\$context['loop'] = [\n")
061                  ->write("  'parent' => \$context['_parent'],\n")
062                  ->write("  'index0' => 0,\n")
063                  ->write("  'index'  => 1,\n")
064                  ->write("  'first'  => true,\n")
065                  ->write("];\n")
066              ;
067   
068              if (!$this->getAttribute('ifexpr')) {
069                  $compiler
070                      ->write("if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof \Countable)) {\n")
071                      ->indent()
072                      ->write("\$length = count(\$context['_seq']);\n")
073                      ->write("\$context['loop']['revindex0'] = \$length - 1;\n")
074                      ->write("\$context['loop']['revindex'] = \$length;\n")
075                      ->write("\$context['loop']['length'] = \$length;\n")
076                      ->write("\$context['loop']['last'] = 1 === \$length;\n")
077                      ->outdent()
078                      ->write("}\n")
079                  ;
080              }
081          }
082   
083          $this->loop->setAttribute('else', $this->hasNode('else'));
084          $this->loop->setAttribute('with_loop', $this->getAttribute('with_loop'));
085          $this->loop->setAttribute('ifexpr', $this->getAttribute('ifexpr'));
086   
087          $compiler
088              ->write("foreach (\$context['_seq'] as ")
089              ->subcompile($this->getNode('key_target'))
090              ->raw(' => ')
091              ->subcompile($this->getNode('value_target'))
092              ->raw(") {\n")
093              ->indent()
094              ->subcompile($this->getNode('body'))
095              ->outdent()
096              ->write("}\n")
097          ;
098   
099          if ($this->hasNode('else')) {
100              $compiler
101                  ->write("if (!\$context['_iterated']) {\n")
102                  ->indent()
103                  ->subcompile($this->getNode('else'))
104                  ->outdent()
105                  ->write("}\n")
106              ;
107          }
108   
109          $compiler->write("\$_parent = \$context['_parent'];\n");
110   
111          // remove some "private" loop variables (needed for nested loops)
112          $compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\''.$this->getNode('key_target')->getAttribute('name').'\'], $context[\''.$this->getNode('value_target')->getAttribute('name').'\'], $context[\'_parent\'], $context[\'loop\']);'."\n");
113   
114          // keep the values set in the inner context for variables defined in the outer context
115          $compiler->write("\$context = array_intersect_key(\$context, \$_parent) + \$_parent;\n");
116      }
117  }
118   
119  class_alias('Twig\Node\ForNode', 'Twig_Node_For');
120