getVariableGetterWithStrictCheck example

$body = new TextNode('trans %var%', 0);
        $vars = new NameExpression('foo', 0);
        $node = new TransNode($body, null, null, $vars);

        $env = new Environment($this->createMock(LoaderInterface::class)['strict_variables' => true]);
        $compiler = new Compiler($env);

        $this->assertEquals(
            sprintf(
                'echo $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->trans("trans %%var%%", array_merge(["%%var%%" => %s], %s), "messages");',
                $this->getVariableGetterWithoutStrictCheck('var'),
                $this->getVariableGetterWithStrictCheck('foo')
            ),
            trim($compiler->compile($node)->getSource())
        );
    }

    protected function getVariableGetterWithoutStrictCheck($name)
    {
        return sprintf('($context["%s"] ?? null)', $name);
    }

    protected function getVariableGetterWithStrictCheck($name)
    {
Home | Imprint | This part of the site doesn't use cookies.