ConstantExpression example

$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(
                    new NameExpression('form', 1),
                    new ArrayExpression([
                        
$visitor->enable();
        $visitor->enterNode($node$env);
        $visitor->leaveNode($node$env);
        $this->assertEquals($expectedMessages$visitor->getMessages());
    }

    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]]);
    }

    
if ($label instanceof ConstantExpression) {
                        // If the label argument is given as a constant, we can either                         // strip it away if it is empty, or integrate it into the array                         // of variables at compile time.                         $labelIsExpression = false;

                        // Only insert the label into the array if it is not empty                         if (!twig_test_empty($label->getAttribute('value'))) {
                            $originalVariables = $variables;
                            $variables = new ArrayExpression([]$lineno);
                            $labelKey = new ConstantExpression('label', $lineno);

                            if (null !== $originalVariables) {
                                foreach ($originalVariables->getKeyValuePairs() as $pair) {
                                    // Don't copy the original label attribute over if it exists                                     if ((string) $labelKey !== (string) $pair['key']) {
                                        $variables->addElement($pair['value']$pair['key']);
                                    }
                                }
                            }

                            // Insert the label argument into the array
$expr->setAttribute('value', '@Storefront/storefront/utilities/thumbnail.html.twig');

        $variables = new ArrayExpression([]$token->getLine());
        if ($stream->nextIf(Token::NAME_TYPE, 'with')) {
            /** @var ArrayExpression $variables */
            $variables = $this->parser->getExpressionParser()->parseExpression();
        }

        $stream->next();

        $variables->addElement(
            new ConstantExpression($className$token->getLine()),
            new ConstantExpression('name', $token->getLine())
        );

        return new SwInclude($expr$variables, false, false, $token->getLine()$this->getTag());
    }

    public function getTag(): string
    {
        return 'sw_thumbnails';
    }
}
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'));
    }

    public function testCompile()
    {
if ($body instanceof ConstantExpression) {
            $msg = $body->getAttribute('value');
        } elseif ($body instanceof TextNode) {
            $msg = $body->getAttribute('data');
        } else {
            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);
                }
            }
        }

        
$this->getVariableGetter('form')
            ),
            trim($compiler->compile($node)->getSource())
        );
    }

    public function testCompileWidgetWithVariables()
    {
        $arguments = new Node([
            new NameExpression('form', 0),
            new ArrayExpression([
                new ConstantExpression('foo', 0),
                new ConstantExpression('bar', 0),
            ], 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\', ["foo" => "bar"])',
                
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FilterExpression;
use Twig\Node\ModuleNode;
use Twig\Node\Node;
use Twig\Source;

class TwigNodeProvider
{
    public static function getModule($content)
    {
        return new ModuleNode(
            new ConstantExpression($content, 0),
            null,
            new ArrayExpression([], 0),
            new ArrayExpression([], 0),
            new ArrayExpression([], 0),
            null,
            new Source('', '')
        );
    }

    public static function getTransFilter($message$domain = null, $arguments = null)
    {
        
$variables = new ArrayExpression([]$token->getLine());

        if ($stream->nextIf(Token::NAME_TYPE, 'style')) {
            /** @var ArrayExpression $variables */
            $variables = $this->parser->getExpressionParser()->parseExpression();
        }

        $stream->next();

        $variables->addElement(
            new ConstantExpression($icon$token->getLine()),
            new ConstantExpression('name', $token->getLine())
        );

        return new SwInclude($expr$variables, false, false, $token->getLine()$this->getTag());
    }

    public function getTag(): string
    {
        return 'sw_icon';
    }
}
Home | Imprint | This part of the site doesn't use cookies.