diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-04 17:50:34 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-04 17:50:34 +0200 |
commit | 46b77928f746a4231d064774b5b67fd892c7ce86 (patch) | |
tree | e3ea690b3f0def1744ddae758923cf92171ef985 /vendor/symfony/twig-bridge/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php | |
parent | 68abd9c71b1d2f7bb2e9d21819584d1d15005b25 (diff) | |
download | wallabag-46b77928f746a4231d064774b5b67fd892c7ce86.tar.gz wallabag-46b77928f746a4231d064774b5b67fd892c7ce86.tar.zst wallabag-46b77928f746a4231d064774b5b67fd892c7ce86.zip |
rm vendor
Diffstat (limited to 'vendor/symfony/twig-bridge/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php')
-rw-r--r-- | vendor/symfony/twig-bridge/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php deleted file mode 100644 index 592c2506..00000000 --- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php +++ /dev/null | |||
@@ -1,137 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Bridge\Twig\NodeVisitor; | ||
13 | |||
14 | use Symfony\Bridge\Twig\Node\TransNode; | ||
15 | |||
16 | /** | ||
17 | * TranslationNodeVisitor extracts translation messages. | ||
18 | * | ||
19 | * @author Fabien Potencier <fabien@symfony.com> | ||
20 | */ | ||
21 | class TranslationNodeVisitor implements \Twig_NodeVisitorInterface | ||
22 | { | ||
23 | const UNDEFINED_DOMAIN = '_undefined'; | ||
24 | |||
25 | private $enabled = false; | ||
26 | private $messages = array(); | ||
27 | |||
28 | public function enable() | ||
29 | { | ||
30 | $this->enabled = true; | ||
31 | $this->messages = array(); | ||
32 | } | ||
33 | |||
34 | public function disable() | ||
35 | { | ||
36 | $this->enabled = false; | ||
37 | $this->messages = array(); | ||
38 | } | ||
39 | |||
40 | public function getMessages() | ||
41 | { | ||
42 | return $this->messages; | ||
43 | } | ||
44 | |||
45 | /** | ||
46 | * {@inheritdoc} | ||
47 | */ | ||
48 | public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env) | ||
49 | { | ||
50 | if (!$this->enabled) { | ||
51 | return $node; | ||
52 | } | ||
53 | |||
54 | if ( | ||
55 | $node instanceof \Twig_Node_Expression_Filter && | ||
56 | 'trans' === $node->getNode('filter')->getAttribute('value') && | ||
57 | $node->getNode('node') instanceof \Twig_Node_Expression_Constant | ||
58 | ) { | ||
59 | // extract constant nodes with a trans filter | ||
60 | $this->messages[] = array( | ||
61 | $node->getNode('node')->getAttribute('value'), | ||
62 | $this->getReadDomainFromArguments($node->getNode('arguments'), 1), | ||
63 | ); | ||
64 | } elseif ( | ||
65 | $node instanceof \Twig_Node_Expression_Filter && | ||
66 | 'transchoice' === $node->getNode('filter')->getAttribute('value') && | ||
67 | $node->getNode('node') instanceof \Twig_Node_Expression_Constant | ||
68 | ) { | ||
69 | // extract constant nodes with a trans filter | ||
70 | $this->messages[] = array( | ||
71 | $node->getNode('node')->getAttribute('value'), | ||
72 | $this->getReadDomainFromArguments($node->getNode('arguments'), 2), | ||
73 | ); | ||
74 | } elseif ($node instanceof TransNode) { | ||
75 | // extract trans nodes | ||
76 | $this->messages[] = array( | ||
77 | $node->getNode('body')->getAttribute('data'), | ||
78 | $this->getReadDomainFromNode($node->getNode('domain')), | ||
79 | ); | ||
80 | } | ||
81 | |||
82 | return $node; | ||
83 | } | ||
84 | |||
85 | /** | ||
86 | * {@inheritdoc} | ||
87 | */ | ||
88 | public function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env) | ||
89 | { | ||
90 | return $node; | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * {@inheritdoc} | ||
95 | */ | ||
96 | public function getPriority() | ||
97 | { | ||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | /** | ||
102 | * @param \Twig_Node $arguments | ||
103 | * @param int $index | ||
104 | * | ||
105 | * @return string|null | ||
106 | */ | ||
107 | private function getReadDomainFromArguments(\Twig_Node $arguments, $index) | ||
108 | { | ||
109 | if ($arguments->hasNode('domain')) { | ||
110 | $argument = $arguments->getNode('domain'); | ||
111 | } elseif ($arguments->hasNode($index)) { | ||
112 | $argument = $arguments->getNode($index); | ||
113 | } else { | ||
114 | return null; | ||
115 | } | ||
116 | |||
117 | return $this->getReadDomainFromNode($argument); | ||
118 | } | ||
119 | |||
120 | /** | ||
121 | * @param \Twig_Node $node | ||
122 | * | ||
123 | * @return string|null | ||
124 | */ | ||
125 | private function getReadDomainFromNode(\Twig_Node $node = null) | ||
126 | { | ||
127 | if (null === $node) { | ||
128 | return null; | ||
129 | } | ||
130 | |||
131 | if ($node instanceof \Twig_Node_Expression_Constant) { | ||
132 | return $node->getAttribute('value'); | ||
133 | } | ||
134 | |||
135 | return self::UNDEFINED_DOMAIN; | ||
136 | } | ||
137 | } | ||