NameExpression example

return [$body$vars];
        }

        preg_match_all('/(?<!%)%([^%]+)%/', $msg$matches);

        foreach ($matches[1] as $var) {
            $key = new ConstantExpression('%'.$var.'%', $body->getTemplateLine());
            if (!$vars->hasElement($key)) {
                if ('count' === $var && $this->hasNode('count')) {
                    $vars->addElement($this->getNode('count')$key);
                } else {
                    $varExpr = new NameExpression($var$body->getTemplateLine());
                    $varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck);
                    $vars->addElement($varExpr$key);
                }
            }
        }

        return [new ConstantExpression(str_replace('%%', '%', trim($msg))$body->getTemplateLine())$vars];
    }
}
EOTXT;

        $this->assertSame($expected$compiler->compile($node, 1)->getSource());
    }

    public function testOneVar()
    {
        $vars = new Node([
            new NameExpression('foo', 7),
        ]);
        $node = new DumpNode('bar', $vars, 7);

        $env = new Environment($this->createMock(LoaderInterface::class));
        $compiler = new Compiler($env);

        $expected = <<<'EOTXT' if ($this->env->isDebug()) { // line 7 \Symfony\Component\VarDumper\VarDumper::dump(%foo%); }


    public function testMessageExtractionWithInvalidDomainNode()
    {
        $message = 'new key';

        $node = new FilterExpression(
            new ConstantExpression($message, 0),
            new ConstantExpression('trans', 0),
            new Node([
                new ArrayExpression([], 0),
                new NameExpression('variable', 0),
            ]),
            0
        );

        $this->testMessagesExtraction($node[[$message, TranslationNodeVisitor::UNDEFINED_DOMAIN]]);
    }

    public static function getMessagesExtractionTestData()
    {
        $message = 'new key';
        $domain = 'domain';

        
$this->scope = $this->scope->enter();
        }

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

                return $node;
            } else {
                $var = $this->getVarName();
                $name = new AssignNameExpression($var$node->getTemplateLine());
                $this->scope->set('domain', new NameExpression($var$node->getTemplateLine()));

                return new SetNode(false, new Node([$name])new Node([$node->getNode('expr')])$node->getTemplateLine());
            }
        }

        if (!$this->scope->has('domain')) {
            return $node;
        }

        if ($node instanceof FilterExpression && 'trans' === $node->getNode('filter')->getAttribute('value')) {
            $arguments = $node->getNode('arguments');
            
$expected->setSourceContext($source);

        $this->assertEquals($expected$parser->parse($stream)->getNode('body')->getNode(0));
    }

    public static function getTestsForFormTheme()
    {
        return [
            [
                '{% form_theme form "tpl1" %}',
                new FormThemeNode(
                    new NameExpression('form', 1),
                    new ArrayExpression([
                        new ConstantExpression(0, 1),
                        new ConstantExpression('tpl1', 1),
                    ], 1),
                    1,
                    'form_theme'
                ),
            ],
            [
                '{% form_theme form "tpl1" "tpl2" %}',
                new FormThemeNode(
                    
use Twig\Node\Expression\NameExpression;
use Twig\Node\TextNode;

/** * @author Asmir Mustafic <goetas@gmail.com> */
class TransNodeTest extends TestCase
{
    public function testCompileStrict()
    {
        $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')
            ),
            
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Node;

class FormThemeTest extends TestCase
{
    use RuntimeLoaderProvider;

    public function testConstructor()
    {
        $form = new NameExpression('form', 0);
        $resources = new Node([
            new ConstantExpression('tpl1', 0),
            new ConstantExpression('tpl2', 0),
        ]);

        $node = new FormThemeNode($form$resources, 0);

        $this->assertEquals($form$node->getNode('form'));
        $this->assertEquals($resources$node->getNode('resources'));
        $this->assertFalse($node->getAttribute('only'));
    }

    
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\ConditionalExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Node;

class SearchAndRenderBlockNodeTest extends TestCase
{
    public function testCompileWidget()
    {
        $arguments = new Node([
            new NameExpression('form', 0),
        ]);

        $node = new SearchAndRenderBlockNode('form_widget', $arguments, 0);

        $compiler = new Compiler(new Environment($this->createMock(LoaderInterface::class)));

        $this->assertEquals(
            sprintf(
                '$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'widget\')',
                $this->getVariableGetter('form')
            ),
            
Home | Imprint | This part of the site doesn't use cookies.