8000 The <bind> tag does not support inner collections · Issue #50046 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

The <bind> tag does not support inner collections #50046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zerustech opened this issue Apr 18, 2023 · 4 comments
Closed

The <bind> tag does not support inner collections #50046

zerustech opened this issue Apr 18, 2023 · 4 comments

Comments

@zerustech
Copy link
Contributor
zerustech commented Apr 18, 2023

Symfony version(s) affected

6.2.0

Description

The inner collection in the following code snippet is ignored:

<bind key="$foo" type="collection">
    <bind key="inner-collection" type="collection">
       <argument>item-1</argument>
       <argument>item-2</argument>
    </bind>
</bind>

How to reproduce

Bind a variable $foo with the following code snippet in a container configuration file, and try to dump this variable in a controller, the inner collection will be empty:

<bind key="$foo" type="collection">
    <bind key="inner-collection" type="collection">
       <argument>item-1</argument>
       <argument>item-2</argument>
    </bind>
</bind>

Possible Solution

Change Symfony\Component\DependencyInjection\Loader\XmlFileLoader as follows:

                 case 'collection': 
-                    $arguments[$key] = $this->getArgumentsAsPhp($arg, $name, $file);
+                    $argumentName = 'bind' === $arg->parentNode->nodeName ? 'argument' : $name;
+                    $arguments[$key] = $this->getArgumentsAsPhp($arg, $argumentName, $file);

Additional Context

No response

@nicolas-grekas
Copy link
Member

Does it work if you go with this?

<bind key="$foo" type="collection">
    <bind key="inner-collection" type="collection">
       <bind>item-1</bind>
8000

       <bind>item-2</bind>
    </bind>
</bind>

@zerustech
Copy link
Contributor Author
zerustech commented Apr 18, 2023

Does it work if you go with this?

<bind key="$foo" type="collection">
    <bind key="inner-collection" type="collection">
       <bind>item-1</bind>
       <bind>item-2</bind>
    </bind>
</bind>

No, it won't work, because the second bind tag is an argument, so, it is not allowed to contain a bind tag.

@zerustech
Copy link
Contributor Author

Does it work if you go with this?

<bind key="$foo" type="collection">
    <bind key="inner-collection" type="collection">
       <bind>item-1</bind>
       <bind>item-2</bind>
    </bind>
</bind>

You can check the node types of bind, and argument nodes in services-1.0.xsd

@nicolas-grekas
Copy link
Member

OK, got it thanks.
That line is wrong to me:
<xsd:element name="bind" type="argument" minOccurs="0" maxOccurs="unbounded" />
it should be
<xsd:element name="argument" type="argument" minOccurs="0" maxOccurs="unbounded" />

In order not to break BC, let's add the new line after the existing one and adapt the code to read from both tags, and include your fix?
Can you please send a PR doing so, with test cases?

zerustech added a commit to zerustech/symfony that referenced this issue Apr 19, 2023
nicolas-grekas added a commit that referenced this issue Apr 19, 2023
…en using `<bind>` (zerustech)

This PR was merged into the 6.2 branch.

Discussion
----------

[DependencyInjection] Fix support for inner collections when using `<bind>`

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #50046
| License       | MIT

Commits
-------

4634eeb [DependencyInjection] Fix support for inner collections when using `<bind>`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0