Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

For.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 4.26 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of Twig.
 005   *
 006   * (c) 2009 Fabien Potencier
 007   * (c) 2009 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  /**
 014   * Represents a for node.
 015   *
 016   * @author Fabien Potencier <fabien@symfony.com>
 017   */
 018  class Twig_Node_For extends Twig_Node
 019  {
 020      protected $loop;
 021   
 022      public function __construct(Twig_Node_Expression_AssignName $keyTarget, Twig_Node_Expression_AssignName $valueTarget, Twig_Node_Expression $seq, Twig_Node_Expression $ifexpr = null, Twig_NodeInterface $body, Twig_NodeInterface $else = null, $lineno, $tag = null)
 023      {
 024          $body = new Twig_Node(array($body, $this->loop = new Twig_Node_ForLoop($lineno, $tag)));
 025   
 026          if (null !== $ifexpr) {
 027              $body = new Twig_Node_If(new Twig_Node(array($ifexpr, $body)), null, $lineno, $tag);
 028          }
 029   
 030          parent::__construct(array('key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body, 'else' => $else), array('with_loop' => true, 'ifexpr' => null !== $ifexpr), $lineno, $tag);
 031      }
 032   
 033      /**
 034       * Compiles the node to PHP.
 035       *
 036       * @param Twig_Compiler A Twig_Compiler instance
 037       */
 038      public function compile(Twig_Compiler $compiler)
 039      {
 040          $compiler
 041              ->addDebugInfo($this)
 042              // the (array) cast bypasses a PHP 5.2.6 bug
 043              ->write("\$context['_parent'] = (array) \$context;\n")
 044              ->write("\$context['_seq'] = twig_ensure_traversable(")
 045              ->subcompile($this->getNode('seq'))
 046              ->raw(");\n")
 047          ;
 048   
 049          if (null !== $this->getNode('else')) {
 050              $compiler->write("\$context['_iterated'] = false;\n");
 051          }
 052   
 053          if ($this->getAttribute('with_loop')) {
 054              $compiler
 055                  ->write("\$context['loop'] = array(\n")
 056                  ->write("  'parent' => \$context['_parent'],\n")
 057                  ->write("  'index0' => 0,\n")
 058                  ->write("  'index'  => 1,\n")
 059                  ->write("  'first'  => true,\n")
 060                  ->write(");\n")
 061              ;
 062   
 063              if (!$this->getAttribute('ifexpr')) {
 064                  $compiler
 065                      ->write("if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof Countable)) {\n")
 066                      ->indent()
 067                      ->write("\$length = count(\$context['_seq']);\n")
 068                      ->write("\$context['loop']['revindex0'] = \$length - 1;\n")
 069                      ->write("\$context['loop']['revindex'] = \$length;\n")
 070                      ->write("\$context['loop']['length'] = \$length;\n")
 071                      ->write("\$context['loop']['last'] = 1 === \$length;\n")
 072                      ->outdent()
 073                      ->write("}\n")
 074                  ;
 075              }
 076          }
 077   
 078          $this->loop->setAttribute('else', null !== $this->getNode('else'));
 079          $this->loop->setAttribute('with_loop', $this->getAttribute('with_loop'));
 080          $this->loop->setAttribute('ifexpr', $this->getAttribute('ifexpr'));
 081   
 082          $compiler
 083              ->write("foreach (\$context['_seq'] as ")
 084              ->subcompile($this->getNode('key_target'))
 085              ->raw(" => ")
 086              ->subcompile($this->getNode('value_target'))
 087              ->raw(") {\n")
 088              ->indent()
 089              ->subcompile($this->getNode('body'))
 090              ->outdent()
 091              ->write("}\n")
 092          ;
 093   
 094          if (null !== $this->getNode('else')) {
 095              $compiler
 096                  ->write("if (!\$context['_iterated']) {\n")
 097                  ->indent()
 098                  ->subcompile($this->getNode('else'))
 099                  ->outdent()
 100                  ->write("}\n")
 101              ;
 102          }
 103   
 104          $compiler->write("\$_parent = \$context['_parent'];\n");
 105   
 106          // remove some "private" loop variables (needed for nested loops)
 107          $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");
 108   
 109          // keep the values set in the inner context for variables defined in the outer context
 110          $compiler->write("\$context = array_intersect_key(\$context, \$_parent) + \$_parent;\n");
 111      }
 112  }
 113