| 148 |
lars |
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\Component\Translation\Extractor\Visitor;
|
|
|
13 |
|
|
|
14 |
use PhpParser\Node;
|
|
|
15 |
use PhpParser\NodeVisitor;
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* @author Mathieu Santostefano <msantostefano@protonmail.com>
|
|
|
19 |
*/
|
|
|
20 |
final class TransMethodVisitor extends AbstractVisitor implements NodeVisitor
|
|
|
21 |
{
|
|
|
22 |
public function beforeTraverse(array $nodes): ?Node
|
|
|
23 |
{
|
|
|
24 |
return null;
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
public function enterNode(Node $node): ?Node
|
|
|
28 |
{
|
|
|
29 |
if (!$node instanceof Node\Expr\MethodCall && !$node instanceof Node\Expr\FuncCall) {
|
|
|
30 |
return null;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
if (!\is_string($node->name) && !$node->name instanceof Node\Identifier && !$node->name instanceof Node\Name) {
|
|
|
34 |
return null;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
$name = (string) $node->name;
|
|
|
38 |
|
|
|
39 |
if ('trans' === $name || 't' === $name) {
|
|
|
40 |
$nodeHasNamedArguments = $this->hasNodeNamedArguments($node);
|
|
|
41 |
if (!$messages = $this->getStringArguments($node, $nodeHasNamedArguments ? 'message' : 0)) {
|
|
|
42 |
return null;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
$domain = $this->getStringArguments($node, $nodeHasNamedArguments ? 'domain' : 2)[0] ?? null;
|
|
|
46 |
|
|
|
47 |
foreach ($messages as $message) {
|
|
|
48 |
$this->addMessageToCatalogue($message, $domain, $node->getStartLine());
|
|
|
49 |
}
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
return null;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
public function leaveNode(Node $node): ?Node
|
|
|
56 |
{
|
|
|
57 |
return null;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public function afterTraverse(array $nodes): ?Node
|
|
|
61 |
{
|
|
|
62 |
return null;
|
|
|
63 |
}
|
|
|
64 |
}
|