Scope example



namespace Symfony\Bridge\Twig\Tests\NodeVisitor;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\NodeVisitor\Scope;

class ScopeTest extends TestCase
{
    public function testScopeInitiation()
    {
        $scope = new Scope();
        $scope->enter();
        $this->assertNull($scope->get('test'));
    }
}
use Twig\NodeVisitor\AbstractNodeVisitor;

/** * @author Fabien Potencier <fabien@symfony.com> */
final class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
{
    private Scope $scope;

    public function __construct()
    {
        $this->scope = new Scope();
    }

    protected function doEnterNode(Node $node, Environment $env): Node
    {
        if ($node instanceof BlockNode || $node instanceof ModuleNode) {
            $this->scope = $this->scope->enter();
        }

        if ($node instanceof TransDefaultDomainNode) {
            if ($node->getNode('expr') instanceof ConstantExpression) {
                $this->scope->set('domain', $node->getNode('expr'));

                
Home | Imprint | This part of the site doesn't use cookies.