Files
ave-cms/adminx/Support/Twig/AdminLocaleNodeVisitor.php
T
2026-07-27 12:58:44 +03:00

58 lines
1.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/*
|--------------------------------------------------------------------------------------
| AVE.cms
|--------------------------------------------------------------------------------------
| @package AVE.cms
| @file adminx/Support/Twig/AdminLocaleNodeVisitor.php
| @author AVE.cms <support@ave-cms.ru>
| @copyright 2007-2026 (c) AVE.cms
| @link https://ave-cms.ru
| @version 3.3
*/
namespace App\Adminx\Support\Twig;
defined('BASEPATH') || die('Direct access to this location is not allowed.');
use Twig\Environment;
use Twig\Node\Node;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\TextNode;
use Twig\NodeVisitor\NodeVisitorInterface;
class AdminLocaleNodeVisitor implements NodeVisitorInterface
{
public function enterNode(Node $node, Environment $environment): Node
{
return $node;
}
public function leaveNode(Node $node, Environment $environment): ?Node
{
if ($node instanceof TextNode && !$node instanceof AdminTextNode) {
return new AdminTextNode(
(string) $node->getAttribute('data'),
(int) $node->getTemplateLine()
);
}
if ($node instanceof ConstantExpression && !$node instanceof AdminConstantExpression) {
$value = $node->getAttribute('value');
if (is_string($value) && preg_match('/[А-Яа-яЁё]/u', $value)) {
return new AdminConstantExpression($value, (int) $node->getTemplateLine());
}
}
return $node;
}
public function getPriority()
{
return 0;
}
}