Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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

SandboxNodeVisitor.php

Zuletzt modifiziert: 01.05.2026, 11:27 - Dateigröße: 4.32 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of Twig.
 005   *
 006   * (c) Fabien Potencier
 007   *
 008   * For the full copyright and license information, please view the LICENSE
 009   * file that was distributed with this source code.
 010   */
 011   
 012  namespace Twig\NodeVisitor;
 013   
 014  use Twig\Environment;
 015  use Twig\Node\CheckSecurityCallNode;
 016  use Twig\Node\CheckSecurityNode;
 017  use Twig\Node\CheckToStringNode;
 018  use Twig\Node\Expression\Binary\ConcatBinary;
 019  use Twig\Node\Expression\Binary\RangeBinary;
 020  use Twig\Node\Expression\FilterExpression;
 021  use Twig\Node\Expression\FunctionExpression;
 022  use Twig\Node\Expression\GetAttrExpression;
 023  use Twig\Node\Expression\NameExpression;
 024  use Twig\Node\ModuleNode;
 025  use Twig\Node\Node;
 026  use Twig\Node\PrintNode;
 027  use Twig\Node\SetNode;
 028   
 029  /**
 030   * @author Fabien Potencier <fabien@symfony.com>
 031   */
 032  final class SandboxNodeVisitor extends AbstractNodeVisitor
 033  {
 034      private $inAModule = false;
 035      private $tags;
 036      private $filters;
 037      private $functions;
 038   
 039      private $needsToStringWrap = false;
 040   
 041      protected function doEnterNode(Node $node, Environment $env)
 042      {
 043          if ($node instanceof ModuleNode) {
 044              $this->inAModule = true;
 045              $this->tags = [];
 046              $this->filters = [];
 047              $this->functions = [];
 048   
 049              return $node;
 050          } elseif ($this->inAModule) {
 051              // look for tags
 052              if ($node->getNodeTag() && !isset($this->tags[$node->getNodeTag()])) {
 053                  $this->tags[$node->getNodeTag()] = $node;
 054              }
 055   
 056              // look for filters
 057              if ($node instanceof FilterExpression && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) {
 058                  $this->filters[$node->getNode('filter')->getAttribute('value')] = $node;
 059              }
 060   
 061              // look for functions
 062              if ($node instanceof FunctionExpression && !isset($this->functions[$node->getAttribute('name')])) {
 063                  $this->functions[$node->getAttribute('name')] = $node;
 064              }
 065   
 066              // the .. operator is equivalent to the range() function
 067              if ($node instanceof RangeBinary && !isset($this->functions['range'])) {
 068                  $this->functions['range'] = $node;
 069              }
 070   
 071              if ($node instanceof PrintNode) {
 072                  $this->needsToStringWrap = true;
 073                  $this->wrapNode($node, 'expr');
 074              }
 075   
 076              if ($node instanceof SetNode && !$node->getAttribute('capture')) {
 077                  $this->needsToStringWrap = true;
 078              }
 079   
 080              // wrap outer nodes that can implicitly call __toString()
 081              if ($this->needsToStringWrap) {
 082                  if ($node instanceof ConcatBinary) {
 083                      $this->wrapNode($node, 'left');
 084                      $this->wrapNode($node, 'right');
 085                  }
 086                  if ($node instanceof FilterExpression) {
 087                      $this->wrapNode($node, 'node');
 088                      $this->wrapArrayNode($node, 'arguments');
 089                  }
 090                  if ($node instanceof FunctionExpression) {
 091                      $this->wrapArrayNode($node, 'arguments');
 092                  }
 093              }
 094          }
 095   
 096          return $node;
 097      }
 098   
 099      protected function doLeaveNode(Node $node, Environment $env)
 100      {
 101          if ($node instanceof ModuleNode) {
 102              $this->inAModule = false;
 103   
 104              $node->setNode('constructor_end', new Node([new CheckSecurityCallNode(), $node->getNode('constructor_end')]));
 105              $node->setNode('class_end', new Node([new CheckSecurityNode($this->filters, $this->tags, $this->functions), $node->getNode('class_end')]));
 106          } elseif ($this->inAModule) {
 107              if ($node instanceof PrintNode || $node instanceof SetNode) {
 108                  $this->needsToStringWrap = false;
 109              }
 110          }
 111   
 112          return $node;
 113      }
 114   
 115      private function wrapNode(Node $node, string $name)
 116      {
 117          $expr = $node->getNode($name);
 118          if ($expr instanceof NameExpression || $expr instanceof GetAttrExpression) {
 119              $node->setNode($name, new CheckToStringNode($expr));
 120          }
 121      }
 122   
 123      private function wrapArrayNode(Node $node, string $name)
 124      {
 125          $args = $node->getNode($name);
 126          foreach ($args as $name => $_) {
 127              $this->wrapNode($args, $name);
 128          }
 129      }
 130   
 131      public function getPriority()
 132      {
 133          return 0;
 134      }
 135  }
 136   
 137  class_alias('Twig\NodeVisitor\SandboxNodeVisitor', 'Twig_NodeVisitor_Sandbox');
 138