addElement example

while (!$stream->test(/* Token::PUNCTUATION_TYPE */ 9, ']')) {
            if (!$first) {
                $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ',', 'An array element must be followed by a comma');

                // trailing ,?                 if ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, ']')) {
                    break;
                }
            }
            $first = false;

            $node->addElement($this->parseExpression());
        }
        $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ']', 'An opened array is not properly closed');

        return $node;
    }

    public function parseHashExpression()
    {
        $stream = $this->parser->getStream();
        $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, '{', 'A hash element was expected');

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

        return [new ConstantExpression(str_replace('%%', '%', trim($msg))$body->getTemplateLine())$vars];
    }
}
while (!$this->stream->current->test(Token::PUNCTUATION_TYPE, ']')) {
            if (!$first) {
                $this->stream->expect(Token::PUNCTUATION_TYPE, ',', 'An array element must be followed by a comma');

                // trailing ,?                 if ($this->stream->current->test(Token::PUNCTUATION_TYPE, ']')) {
                    break;
                }
            }
            $first = false;

            $node->addElement($this->parseExpression());
        }
        $this->stream->expect(Token::PUNCTUATION_TYPE, ']', 'An opened array is not properly closed');

        return $node;
    }

    /** * @return Node\ArrayNode */
    public function parseHashExpression()
    {
        
// 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                             $variables->addElement($label$labelKey);
                        }
                    } else {
                        // The label argument is not a constant, but some kind of                         // expression. This expression needs to be evaluated at runtime.                         // Depending on the result (whether it is null or not), the

        foreach ($this->elements as $element) {
            if ($element->getName() === $name) {
                $element->setType($type);
                if ($options !== null) {
                    $element->setOptions($options);
                }

                return $this;
            }
        }
        $this->addElement($type$name$options);

        return $this;
    }

    /** * @param string|Element $element * * @return Form */
    public function removeElement($element)
    {
        
$className = $expr->getAttribute('value');
        $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';
    }
}

    public function testParse($node$expression$names = [])
    {
        $lexer = new Lexer();
        $parser = new Parser([]);
        $this->assertEquals($node$parser->parse($lexer->tokenize($expression)$names));
    }

    public static function getParseData()
    {
        $arguments = new Node\ArgumentsNode();
        $arguments->addElement(new Node\ConstantNode('arg1'));
        $arguments->addElement(new Node\ConstantNode(2));
        $arguments->addElement(new Node\ConstantNode(true));

        $arrayNode = new Node\ArrayNode();
        $arrayNode->addElement(new Node\NameNode('bar'));

        return [
            [
                new Node\NameNode('a'),
                'a',
                ['a'],
            ],
if ($this->parser->getStream()->test(Token::NAME_TYPE, 'with')) {
            $this->parser->getStream()->next();
            $resources = $this->parser->getExpressionParser()->parseExpression();

            if ($this->parser->getStream()->nextIf(Token::NAME_TYPE, 'only')) {
                $only = true;
            }
        } else {
            $resources = new ArrayExpression([]$stream->getCurrent()->getLine());
            do {
                $resources->addElement($this->parser->getExpressionParser()->parseExpression());
            } while (!$stream->test(Token::BLOCK_END_TYPE));
        }

        $stream->expect(Token::BLOCK_END_TYPE);

        return new FormThemeNode($form$resources$lineno$this->getTag()$only);
    }

    public function getTag(): string
    {
        return 'form_theme';
    }
'foo.foo', new GetAttrNode(new NameNode('foo')new NameNode('foo'), self::getArrayNode(), GetAttrNode::PROPERTY_CALL)['foo' => new Obj()]],

            ['foo.foo({"b": "a", 0: "b"})', new GetAttrNode(new NameNode('foo')new NameNode('foo'), self::getArrayNode(), GetAttrNode::METHOD_CALL)['foo' => new Obj()]],
            ['foo[index]', new GetAttrNode(new NameNode('foo')new NameNode('index'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)],
        ];
    }

    protected static function getArrayNode(): ArrayNode
    {
        $array = new ArrayNode();
        $array->addElement(new ConstantNode('a')new ConstantNode('b'));
        $array->addElement(new ConstantNode('b'));

        return $array;
    }
}

class Obj
{
    public $foo = 'bar';

    public function foo()
    {
$missingArguments[] = $name;
                }
            } else {
                throw new SyntaxError(sprintf('Value for argument "%s" is required for %s "%s".', $name$callType$callName)$this->getTemplateLine()$this->getSourceContext());
            }
        }

        if ($isVariadic) {
            $arbitraryArguments = $isPhpVariadic ? new VariadicExpression([], -1) : new ArrayExpression([], -1);
            foreach ($parameters as $key => $value) {
                if (\is_int($key)) {
                    $arbitraryArguments->addElement($value);
                } else {
                    $arbitraryArguments->addElement($valuenew ConstantExpression($key, -1));
                }
                unset($parameters[$key]);
            }

            if ($arbitraryArguments->count()) {
                $arguments = array_merge($arguments$optionalArguments);
                $arguments[] = $arbitraryArguments;
            }
        }

        
namespace Symfony\Component\ExpressionLanguage\Tests\Node;

use Symfony\Component\ExpressionLanguage\Node\ArrayNode;
use Symfony\Component\ExpressionLanguage\Node\ConstantNode;

class ArrayNodeTest extends AbstractNodeTestCase
{
    public function testSerialization()
    {
        $node = $this->createArrayNode();
        $node->addElement(new ConstantNode('foo'));

        $serializedNode = serialize($node);
        $unserializedNode = unserialize($serializedNode);

        $this->assertEquals($node$unserializedNode);
        $this->assertNotEquals($this->createArrayNode()$unserializedNode);
    }

    public static function getEvaluateData(): array
    {
        return [
            [[
'__logos__',
            [
                'attributes' => [
                    'padding' => '10',
                    'margin' => '5',
                    'layout' => 'anchor',
                    'defaults' => ['labelWidth' => 155, 'anchor' => '100%'],
                ],
            ]
        );

        $fieldSet->addElement(
            $this->createMediaField(
                'mobileLogo',
                '__smartphone__',
                'frontend/_public/src/img/logos/logo--mobile.png',
                ['attributes' => ['lessCompatible' => false]]
            )
        );

        $fieldSet->addElement(
            $this->createMediaField(
                'tabletLogo',
                
throw new InvalidArgumentException('$element must be instance of Shopware\Components\Form\Container\Tab');
        }

        return $this->addTab($element);
    }

    /** * @return $this */
    public function addTab(Tab $element)
    {
        return parent::addElement($element);
    }
}
use Symfony\Component\ExpressionLanguage\Node\ConstantNode;
use Symfony\Component\ExpressionLanguage\Node\NameNode;
use Symfony\Component\ExpressionLanguage\SyntaxError;

class BinaryNodeTest extends AbstractNodeTestCase
{
    use ExpectDeprecationTrait;

    public static function getEvaluateData(): array
    {
        $array = new ArrayNode();
        $array->addElement(new ConstantNode('a'));
        $array->addElement(new ConstantNode('b'));

        return [
            [true, new BinaryNode('or', new ConstantNode(true)new ConstantNode(false))],
            [true, new BinaryNode('||', new ConstantNode(true)new ConstantNode(false))],
            [false, new BinaryNode('and', new ConstantNode(true)new ConstantNode(false))],
            [false, new BinaryNode('&&', new ConstantNode(true)new ConstantNode(false))],

            [0, new BinaryNode('&', new ConstantNode(2)new ConstantNode(4))],
            [6, new BinaryNode('|', new ConstantNode(2)new ConstantNode(4))],
            [6, new BinaryNode('^', new ConstantNode(2)new ConstantNode(4))],

            [
public function createConfig(TabContainer $container)
    {
        $container->addTab($this->createMainConfigTab());

        $tab = $this->createTab(
            'responsive_tab',
            '__responsive_colors__'
        );
        $container->addTab($tab);

        $tab->addElement($this->createBottomTabPanel());
    }

    /** * Helper function to merge default theme colors with color schemes. */
    public function createConfigSets(ArrayCollection $collection)
    {
        $set = new ConfigSet();
        $set->setName('__color_scheme_turquoise__')->setDescription(
            '__color_scheme_turquoise_description__'
        )->setValues(
            
Home | Imprint | This part of the site doesn't use cookies.