Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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

TranslationDefaultDomainNodeVisitor.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 3.55 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of the Symfony package.
 005   *
 006   * (c) Fabien Potencier <fabien@symfony.com>
 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 Symfony\Bridge\Twig\NodeVisitor;
 013   
 014  use Symfony\Bridge\Twig\Node\TransNode;
 015  use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
 016   
 017  /**
 018   * TranslationDefaultDomainNodeVisitor.
 019   *
 020   * @author Fabien Potencier <fabien@symfony.com>
 021   */
 022  class TranslationDefaultDomainNodeVisitor extends \Twig_BaseNodeVisitor
 023  {
 024      /**
 025       * @var Scope
 026       */
 027      private $scope;
 028   
 029      /**
 030       * Constructor.
 031       */
 032      public function __construct()
 033      {
 034          $this->scope = new Scope();
 035      }
 036   
 037      /**
 038       * {@inheritdoc}
 039       */
 040      protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
 041      {
 042          if ($node instanceof \Twig_Node_Block || $node instanceof \Twig_Node_Module) {
 043              $this->scope = $this->scope->enter();
 044          }
 045   
 046          if ($node instanceof TransDefaultDomainNode) {
 047              if ($node->getNode('expr') instanceof \Twig_Node_Expression_Constant) {
 048                  $this->scope->set('domain', $node->getNode('expr'));
 049   
 050                  return $node;
 051              } else {
 052                  $var = $env->getParser()->getVarName();
 053                  $name = new \Twig_Node_Expression_AssignName($var, $node->getLine());
 054                  $this->scope->set('domain', new \Twig_Node_Expression_Name($var, $node->getLine()));
 055   
 056                  return new \Twig_Node_Set(false, new \Twig_Node(array($name)), new \Twig_Node(array($node->getNode('expr'))), $node->getLine());
 057              }
 058          }
 059   
 060          if (!$this->scope->has('domain')) {
 061              return $node;
 062          }
 063   
 064          if ($node instanceof \Twig_Node_Expression_Filter && in_array($node->getNode('filter')->getAttribute('value'), array('trans', 'transchoice'))) {
 065              $arguments = $node->getNode('arguments');
 066              $ind = 'trans' === $node->getNode('filter')->getAttribute('value') ? 1 : 2;
 067              if ($this->isNamedArguments($arguments)) {
 068                  if (!$arguments->hasNode('domain') && !$arguments->hasNode($ind)) {
 069                      $arguments->setNode('domain', $this->scope->get('domain'));
 070                  }
 071              } else {
 072                  if (!$arguments->hasNode($ind)) {
 073                      if (!$arguments->hasNode($ind - 1)) {
 074                          $arguments->setNode($ind - 1, new \Twig_Node_Expression_Array(array(), $node->getLine()));
 075                      }
 076   
 077                      $arguments->setNode($ind, $this->scope->get('domain'));
 078                  }
 079              }
 080          } elseif ($node instanceof TransNode) {
 081              if (null === $node->getNode('domain')) {
 082                  $node->setNode('domain', $this->scope->get('domain'));
 083              }
 084          }
 085   
 086          return $node;
 087      }
 088   
 089      /**
 090       * {@inheritdoc}
 091       */
 092      protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env)
 093      {
 094          if ($node instanceof TransDefaultDomainNode) {
 095              return false;
 096          }
 097   
 098          if ($node instanceof \Twig_Node_Block || $node instanceof \Twig_Node_Module) {
 099              $this->scope = $this->scope->leave();
 100          }
 101   
 102          return $node;
 103      }
 104   
 105      /**
 106       * {@inheritdoc}
 107       */
 108      public function getPriority()
 109      {
 110          return -10;
 111      }
 112   
 113      /**
 114       * @return bool
 115       */
 116      private function isNamedArguments($arguments)
 117      {
 118          foreach ($arguments as $name => $node) {
 119              if (!is_int($name)) {
 120                  return true;
 121              }
 122          }
 123   
 124          return false;
 125      }
 126  }
 127