Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] Allow array attributes for service tags #47364

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

Merged
merged 1 commit into from
Oct 24, 2022

Conversation

aschempp
Copy link
Contributor

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #38339, #38540
License MIT
Doc PR symfony/symfony-docs#...

This adds array attribute support for container service tags as described in #38339. The most notable change is the additions to the XML schema for services, because that's the current limitation for not using array.

This is reopening #38540 as new PR since the other one was ("accidentially") closed 😊
/cc @nicolas-grekas

@carsonbot carsonbot added this to the 6.2 milestone Aug 23, 2022
@aschempp aschempp changed the title Feature/tag array attributes [DependencyInjection] Allow array attributes for service tags Aug 23, 2022
@carsonbot
Copy link

Hey!

I think @nusje2000 has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reopening.
LGTM, just some nitpicking.

@ruudk
Copy link
Contributor

ruudk commented Sep 6, 2022

@aschempp Just wanted to say how happy I am that you didn't give up on this idea and finished the PR 👏 🙌 💙

@nicolas-grekas nicolas-grekas added the ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" label Oct 19, 2022
@nicolas-grekas nicolas-grekas force-pushed the feature/tag-array-attributes branch from 8be8031 to edd8d77 Compare October 24, 2022 09:40
@fabpot
Copy link
Member

fabpot commented Oct 24, 2022

Thank you @aschempp.

@ju1ius
Copy link
Contributor

ju1ius commented Jan 11, 2023

Hi @aschempp, I can't get this feature to work.
The following config:

$configurator->services()
  ->set(Foo::class)
  ->tag('foo', ['bar' => ['baz' => 42]);

throws:

[Symfony\Component\DependencyInjection\Exception\RuntimeException]
at symfony/dependency-injection/Compiler/CheckDefinitionValidityPass.php line 67:
A "tags" attribute must be of a scalar-type for service "App\Foo", tag "foo", attribute "bar".

The tag is accepted by the ContainerConfigurator, but rejected by the CheckDefinitionValidityPass...

Am I missing something or should I open an issue ?

@nicolas-grekas
Copy link
Member

@ju1ius looks like you're the first to actually use the feature 😅
Can you please send us a fix with a test case?

@ju1ius
Copy link
Contributor

ju1ius commented Jan 11, 2023

@nicolas-grekas OK, will take a stab at it during the week.

@ju1ius
Copy link
Contributor

ju1ius commented Jan 12, 2023

@nicolas-grekas Done in #48958 😉

nicolas-grekas added a commit that referenced this pull request Jan 13, 2023
…bute values (ju1ius)

This PR was squashed before being merged into the 6.2 branch.

Discussion
----------

[DependencyInjection] fixes validation of non-scalar attribute values

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #48956
| License       | MIT
| Doc PR        | None

As a follow-up to #47364, this PR updates the `CheckDefinitionValidityPass` to allow (possibly nested) arrays of scalars in service tags attribute values.
Please see #48956 for context.

Commits
-------

88b3e15 [DependencyInjection] fixes validation of non-scalar attribute values
nicolas-grekas added a commit that referenced this pull request Mar 14, 2024
…so a 'name' property (lyrixx)

This PR was merged into the 6.4 branch.

Discussion
----------

[DependencyInjection] fix XmlDumper when a tag contains also a 'name' property

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

Since #47364, the tag can contain an **array** of attributes.
And since #47364, SF uses it to store workflow metadata and also a **name** property.
It likely broke the XML generation, and so it brokes `debug:router` command for instance.
Sorry, I didn't notice it before!

Before the patch, I got that in my container var/cache/dev/App_KernelDevDebugContainer.xml

```xml
<tag>workflow<attribute name="name">article</attribute><attribute name="metadata"><attribute name="title">Manage article</attribute></attribute></tag>
```

After, I got

```xml
<tag name="workflow">
  <attribute name="name">article</attribute>
  <attribute name="metadata">
    <attribute name="title">Manage article</attribute>
  </attribute>
</tag>
```

Commits
-------

4a4b011 [DependencyInjection] fix XmlDumper when a tag contains also a 'name' property
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DependencyInjection Feature ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" Status: Reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for non-scalar tag attributes
8 participants