Skip to content
This repository was archived by the owner on May 19, 2024. It is now read-only.
This repository was archived by the owner on May 19, 2024. It is now read-only.

TwigNodes cannot be used with variables #25

@nziermann

Description

@nziermann

I prepared an example:

{% xlsdocument {format: 'xlsx'} %}
        {% set title = 'test' %}
        {% set style = {columnDimension: {'B': {autoSize: true},'C': {autoSize: true},'D': {autoSize: true},'E': {autoSize: true}}} %}
        {% xlssheet title style %}
        {% endxlssheet %}
{% endxlsdocument %}

What happened: Too many parameters in "data_storage/export.xls.twig"
What I expected: That this call works.

I traced it back to the behaviour of the BaseTokenParser regarding TwigNodeExpressionName. Although style contains an array the type is TwigNodeExpressionName this leads to the base token parser recognizing it as a value type and not as an array.

The following code is responsible for this:

switch ($parameterOptions['type']) {
                    case self::PARAMETER_TYPE_ARRAY:
                        // check if expression is valid array
                        $valid = $expression instanceof \Twig_Node_Expression_Array;
                        break;
                    case self::PARAMETER_TYPE_VALUE:
                        // check if expression is valid value
                        $valid = !($expression instanceof \Twig_Node_Expression_Array);
                        break;
                    default:
                        throw new \InvalidArgumentException('Invalid parameter type');
                }

I'm currently using a workaround with:

switch ($parameterOptions['type']) {
                    case self::PARAMETER_TYPE_ARRAY:
                        // check if expression is valid array
                        $valid = $expression instanceof \Twig_Node_Expression_Array || $expression instanceof \Twig_Node_Expression_Name;
                        break;
                    case self::PARAMETER_TYPE_VALUE:
                        // check if expression is valid value
                        $valid = !($expression instanceof \Twig_Node_Expression_Array) || $expression instanceof \Twig_Node_Expression_Name;
                        break;
                    default:
                        throw new \InvalidArgumentException('Invalid parameter type');
                }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions