-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathRemovingNodeVisitor.php
More file actions
57 lines (47 loc) · 1.25 KB
/
RemovingNodeVisitor.php
File metadata and controls
57 lines (47 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/*
* This file is part of the PHP Translation package.
*
* (c) PHP Translation team <tobias.nyholm@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Translation\Bundle\Twig\Visitor;
use Twig\Environment;
use Twig\Node\Expression\FilterExpression;
use Twig\Node\Node;
/**
* Removes translation metadata filters from the AST.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
final class RemovingNodeVisitor extends AbstractNodeVisitor
{
/**
* @var bool
*/
private $enabled = true;
public function setEnabled(bool $bool): void
{
$this->enabled = $bool;
}
protected function doEnterNode(Node $node, Environment $env): Node
{
if ($this->enabled && $node instanceof FilterExpression) {
$name = $this->getValueFromNode($node);
if ('desc' === $name || 'meaning' === $name) {
return $this->enterNode($node->getNode('node'), $env);
}
}
return $node;
}
protected function doLeaveNode(Node $node, Environment $env): Node
{
return $node;
}
public function getPriority(): int
{
return -1;
}
}