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

TranslationNodeVisitor.php

Zuletzt modifiziert: 01.05.2026, 11:27 - Dateigröße: 3.44 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 Twig\Environment;
 016  use Twig\Node\Expression\ConstantExpression;
 017  use Twig\Node\Expression\FilterExpression;
 018  use Twig\Node\Node;
 019  use Twig\NodeVisitor\AbstractNodeVisitor;
 020   
 021  /**
 022   * TranslationNodeVisitor extracts translation messages.
 023   *
 024   * @author Fabien Potencier <fabien@symfony.com>
 025   */
 026  class TranslationNodeVisitor extends AbstractNodeVisitor
 027  {
 028      const UNDEFINED_DOMAIN = '_undefined';
 029   
 030      private $enabled = false;
 031      private $messages = [];
 032   
 033      public function enable()
 034      {
 035          $this->enabled = true;
 036          $this->messages = [];
 037      }
 038   
 039      public function disable()
 040      {
 041          $this->enabled = false;
 042          $this->messages = [];
 043      }
 044   
 045      public function getMessages()
 046      {
 047          return $this->messages;
 048      }
 049   
 050      /**
 051       * {@inheritdoc}
 052       */
 053      protected function doEnterNode(Node $node, Environment $env)
 054      {
 055          if (!$this->enabled) {
 056              return $node;
 057          }
 058   
 059          if (
 060              $node instanceof FilterExpression &&
 061              'trans' === $node->getNode('filter')->getAttribute('value') &&
 062              $node->getNode('node') instanceof ConstantExpression
 063          ) {
 064              // extract constant nodes with a trans filter
 065              $this->messages[] = [
 066                  $node->getNode('node')->getAttribute('value'),
 067                  $this->getReadDomainFromArguments($node->getNode('arguments'), 1),
 068              ];
 069          } elseif (
 070              $node instanceof FilterExpression &&
 071              'transchoice' === $node->getNode('filter')->getAttribute('value') &&
 072              $node->getNode('node') instanceof ConstantExpression
 073          ) {
 074              // extract constant nodes with a trans filter
 075              $this->messages[] = [
 076                  $node->getNode('node')->getAttribute('value'),
 077                  $this->getReadDomainFromArguments($node->getNode('arguments'), 2),
 078              ];
 079          } elseif ($node instanceof TransNode) {
 080              // extract trans nodes
 081              $this->messages[] = [
 082                  $node->getNode('body')->getAttribute('data'),
 083                  $node->hasNode('domain') ? $this->getReadDomainFromNode($node->getNode('domain')) : null,
 084              ];
 085          }
 086   
 087          return $node;
 088      }
 089   
 090      /**
 091       * {@inheritdoc}
 092       */
 093      protected function doLeaveNode(Node $node, Environment $env)
 094      {
 095          return $node;
 096      }
 097   
 098      /**
 099       * {@inheritdoc}
 100       *
 101       * @return int
 102       */
 103      public function getPriority()
 104      {
 105          return 0;
 106      }
 107   
 108      /**
 109       * @param int $index
 110       *
 111       * @return string|null
 112       */
 113      private function getReadDomainFromArguments(Node $arguments, $index)
 114      {
 115          if ($arguments->hasNode('domain')) {
 116              $argument = $arguments->getNode('domain');
 117          } elseif ($arguments->hasNode($index)) {
 118              $argument = $arguments->getNode($index);
 119          } else {
 120              return null;
 121          }
 122   
 123          return $this->getReadDomainFromNode($argument);
 124      }
 125   
 126      /**
 127       * @return string|null
 128       */
 129      private function getReadDomainFromNode(Node $node)
 130      {
 131          if ($node instanceof ConstantExpression) {
 132              return $node->getAttribute('value');
 133          }
 134   
 135          return self::UNDEFINED_DOMAIN;
 136      }
 137  }
 138