getKeyValuePairs example

class ArgumentsNode extends ArrayNode
{
    public function compile(Compiler $compiler): void
    {
        $this->compileArguments($compiler, false);
    }

    public function toArray(): array
    {
        $array = [];

        foreach ($this->getKeyValuePairs() as $pair) {
            $array[] = $pair['value'];
            $array[] = ', ';
        }
        array_pop($array);

        return $array;
    }
}
// @deprecated tag:v6.6.0 - Remove this check             return false;
        }

        return !\array_intersect($this->templateScopeDetector->getScopes()$scopes) && !str_starts_with($source, '@Storefront');
    }

    private function convertExpressionToArray(AbstractExpression $expression): mixed
    {
        if ($expression instanceof ArrayExpression) {
            $array = [];
            foreach ($expression->getKeyValuePairs() as $pair) {
                if (!$pair['key'] instanceof ConstantExpression) {
                    throw AdapterException::unexpectedTwigExpression($pair['key']);
                }

                $array[$pair['key']->getAttribute('value')] = $this->convertExpressionToArray($pair['value']);
            }

            return $array;
        }

        if ($expression instanceof ConstantExpression) {
            
use Twig\Compiler;

class ArrayExpression extends AbstractExpression
{
    private $index;

    public function __construct(array $elements, int $lineno)
    {
        parent::__construct($elements[]$lineno);

        $this->index = -1;
        foreach ($this->getKeyValuePairs() as $pair) {
            if ($pair['key'] instanceof ConstantExpression && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) {
                $this->index = $pair['key']->getAttribute('value');
            }
        }
    }

    public function getKeyValuePairs(): array
    {
        $pairs = [];
        foreach (array_chunk($this->nodes, 2) as $pair) {
            $pairs[] = [
                
                        // 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                             $variables->addElement($label$labelKey);
                        }
                    } else {
                        

    public function compile(Compiler $compiler): void
    {
        $compiler->raw('[');
        $this->compileArguments($compiler);
        $compiler->raw(']');
    }

    public function evaluate(array $functions, array $values): array
    {
        $result = [];
        foreach ($this->getKeyValuePairs() as $pair) {
            $result[$pair['key']->evaluate($functions$values)] = $pair['value']->evaluate($functions$values);
        }

        return $result;
    }

    public function toArray(): array
    {
        $value = [];
        foreach ($this->getKeyValuePairs() as $pair) {
            $value[$pair['key']->attributes['value']] = $pair['value'];
        }
return;
        }

        $compiler
            ->raw('twig_call_macro($macros[')
            ->repr($this->getNode('node')->getAttribute('name'))
            ->raw('], ')
            ->repr($this->getAttribute('method'))
            ->raw(', [')
        ;
        $first = true;
        foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) {
            if (!$first) {
                $compiler->raw(', ');
            }
            $first = false;

            $compiler->subcompile($pair['value']);
        }
        $compiler
            ->raw('], ')
            ->repr($this->getTemplateLine())
            ->raw(', $context, $this->getSourceContext())');
    }
Home | Imprint | This part of the site doesn't use cookies.