Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
TranslationDefaultDomainNodeVisitor.php
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\TransDefaultDomainNode;
015 use Symfony\Bridge\Twig\Node\TransNode;
016 use Twig\Environment;
017 use Twig\Node\BlockNode;
018 use Twig\Node\Expression\ArrayExpression;
019 use Twig\Node\Expression\AssignNameExpression;
020 use Twig\Node\Expression\ConstantExpression;
021 use Twig\Node\Expression\FilterExpression;
022 use Twig\Node\Expression\NameExpression;
023 use Twig\Node\ModuleNode;
024 use Twig\Node\Node;
025 use Twig\Node\SetNode;
026 use Twig\NodeVisitor\AbstractNodeVisitor;
027
028 /**
029 * @author Fabien Potencier <fabien@symfony.com>
030 */
031 class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
032 {
033 private $scope;
034
035 public function __construct()
036 {
037 $this->scope = new Scope();
038 }
039
040 /**
041 * {@inheritdoc}
042 */
043 protected function doEnterNode(Node $node, Environment $env)
044 {
045 if ($node instanceof BlockNode || $node instanceof ModuleNode) {
046 $this->scope = $this->scope->enter();
047 }
048
049 if ($node instanceof TransDefaultDomainNode) {
050 if ($node->getNode('expr') instanceof ConstantExpression) {
051 $this->scope->set('domain', $node->getNode('expr'));
052
053 return $node;
054 } else {
055 $var = $this->getVarName();
056 $name = new AssignNameExpression($var, $node->getTemplateLine());
057 $this->scope->set('domain', new NameExpression($var, $node->getTemplateLine()));
058
059 return new SetNode(false, new Node([$name]), new Node([$node->getNode('expr')]), $node->getTemplateLine());
060 }
061 }
062
063 if (!$this->scope->has('domain')) {
064 return $node;
065 }
066
067 if ($node instanceof FilterExpression && \in_array($node->getNode('filter')->getAttribute('value'), ['trans', 'transchoice'])) {
068 $arguments = $node->getNode('arguments');
069 $ind = 'trans' === $node->getNode('filter')->getAttribute('value') ? 1 : 2;
070 if ($this->isNamedArguments($arguments)) {
071 if (!$arguments->hasNode('domain') && !$arguments->hasNode($ind)) {
072 $arguments->setNode('domain', $this->scope->get('domain'));
073 }
074 } else {
075 if (!$arguments->hasNode($ind)) {
076 if (!$arguments->hasNode($ind - 1)) {
077 $arguments->setNode($ind - 1, new ArrayExpression([], $node->getTemplateLine()));
078 }
079
080 $arguments->setNode($ind, $this->scope->get('domain'));
081 }
082 }
083 } elseif ($node instanceof TransNode) {
084 if (!$node->hasNode('domain')) {
085 $node->setNode('domain', $this->scope->get('domain'));
086 }
087 }
088
089 return $node;
090 }
091
092 /**
093 * {@inheritdoc}
094 */
095 protected function doLeaveNode(Node $node, Environment $env)
096 {
097 if ($node instanceof TransDefaultDomainNode) {
098 return null;
099 }
100
101 if ($node instanceof BlockNode || $node instanceof ModuleNode) {
102 $this->scope = $this->scope->leave();
103 }
104
105 return $node;
106 }
107
108 /**
109 * {@inheritdoc}
110 *
111 * @return int
112 */
113 public function getPriority()
114 {
115 return -10;
116 }
117
118 /**
119 * @return bool
120 */
121 private function isNamedArguments($arguments)
122 {
123 foreach ($arguments as $name => $node) {
124 if (!\is_int($name)) {
125 return true;
126 }
127 }
128
129 return false;
130 }
131
132 private function getVarName()
133 {
134 return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false));
135 }
136 }
137