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.71 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   * Loops over each item of a sequence.
 015   *
 016   * <pre>
 017   * <ul>
 018   *  {% for user in users %}
 019   *    <li>{{ user.username|e }}</li>
 020   *  {% endfor %}
 021   * </ul>
 022   * </pre>
 023   */
 024  class Twig_TokenParser_For extends Twig_TokenParser
 025  {
 026      /**
 027       * Parses a token and returns a node.
 028       *
 029       * @param Twig_Token $token A Twig_Token instance
 030       *
 031       * @return Twig_NodeInterface A Twig_NodeInterface instance
 032       */
 033      public function parse(Twig_Token $token)
 034      {
 035          $lineno = $token->getLine();
 036          $stream = $this->parser->getStream();
 037          $targets = $this->parser->getExpressionParser()->parseAssignmentExpression();
 038          $stream->expect(Twig_Token::OPERATOR_TYPE, 'in');
 039          $seq = $this->parser->getExpressionParser()->parseExpression();
 040   
 041          $ifexpr = null;
 042          if ($stream->test(Twig_Token::NAME_TYPE, 'if')) {
 043              $stream->next();
 044              $ifexpr = $this->parser->getExpressionParser()->parseExpression();
 045          }
 046   
 047          $stream->expect(Twig_Token::BLOCK_END_TYPE);
 048          $body = $this->parser->subparse(array($this, 'decideForFork'));
 049          if ($stream->next()->getValue() == 'else') {
 050              $stream->expect(Twig_Token::BLOCK_END_TYPE);
 051              $else = $this->parser->subparse(array($this, 'decideForEnd'), true);
 052          } else {
 053              $else = null;
 054          }
 055          $stream->expect(Twig_Token::BLOCK_END_TYPE);
 056   
 057          if (count($targets) > 1) {
 058              $keyTarget = $targets->getNode(0);
 059              $keyTarget = new Twig_Node_Expression_AssignName($keyTarget->getAttribute('name'), $keyTarget->getLine());
 060              $valueTarget = $targets->getNode(1);
 061              $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getLine());
 062          } else {
 063              $keyTarget = new Twig_Node_Expression_AssignName('_key', $lineno);
 064              $valueTarget = $targets->getNode(0);
 065              $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getLine());
 066          }
 067   
 068          if ($ifexpr) {
 069              $this->checkLoopUsageCondition($stream, $ifexpr);
 070              $this->checkLoopUsageBody($stream, $body);
 071          }
 072   
 073          return new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag());
 074      }
 075   
 076      public function decideForFork(Twig_Token $token)
 077      {
 078          return $token->test(array('else', 'endfor'));
 079      }
 080   
 081      public function decideForEnd(Twig_Token $token)
 082      {
 083          return $token->test('endfor');
 084      }
 085   
 086      // the loop variable cannot be used in the condition
 087      protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeInterface $node)
 088      {
 089          if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) {
 090              throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition', $node->getLine(), $stream->getFilename());
 091          }
 092   
 093          foreach ($node as $n) {
 094              if (!$n) {
 095                  continue;
 096              }
 097   
 098              $this->checkLoopUsageCondition($stream, $n);
 099          }
 100      }
 101   
 102      // check usage of non-defined loop-items
 103      // it does not catch all problems (for instance when a for is included into another or when the variable is used in an include)
 104      protected function checkLoopUsageBody(Twig_TokenStream $stream, Twig_NodeInterface $node)
 105      {
 106          if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) {
 107              $attribute = $node->getNode('attribute');
 108              if ($attribute instanceof Twig_Node_Expression_Constant && in_array($attribute->getAttribute('value'), array('length', 'revindex0', 'revindex', 'last'))) {
 109                  throw new Twig_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition', $attribute->getAttribute('value')), $node->getLine(), $stream->getFilename());
 110              }
 111          }
 112   
 113          // should check for parent.loop.XXX usage
 114          if ($node instanceof Twig_Node_For) {
 115              return;
 116          }
 117   
 118          foreach ($node as $n) {
 119              if (!$n) {
 120                  continue;
 121              }
 122   
 123              $this->checkLoopUsageBody($stream, $n);
 124          }
 125      }
 126   
 127      /**
 128       * Gets the tag name associated with this token parser.
 129       *
 130       * @return string The tag name
 131       */
 132      public function getTag()
 133      {
 134          return 'for';
 135      }
 136  }
 137