Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
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 TranslatableMessageVisitor 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\New_) {
30
            return null;
31
        }
32
 
33
        if (!($className = $node->class) instanceof Node\Name) {
34
            return null;
35
        }
36
 
37
        if (!\in_array('TranslatableMessage', $className->parts, true)) {
38
            return null;
39
        }
40
 
200 lars 41
        $firstNamedArgumentIndex = $this->nodeFirstNamedArgumentIndex($node);
148 lars 42
 
200 lars 43
        if (!$messages = $this->getStringArguments($node, 0 < $firstNamedArgumentIndex ? 0 : 'message')) {
148 lars 44
            return null;
45
        }
46
 
200 lars 47
        $domain = $this->getStringArguments($node, 2 < $firstNamedArgumentIndex ? 2 : 'domain')[0] ?? null;
148 lars 48
 
49
        foreach ($messages as $message) {
50
            $this->addMessageToCatalogue($message, $domain, $node->getStartLine());
51
        }
52
 
53
        return null;
54
    }
55
 
56
    public function leaveNode(Node $node): ?Node
57
    {
58
        return null;
59
    }
60
 
61
    public function afterTraverse(array $nodes): ?Node
62
    {
63
        return null;
64
    }
65
}