-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] Support extending AsMessageHandler
attribute
#52898
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
Comments
👍 To make it final. Symfony wouldn't be able to handle any extra capacity added to the child attribute so allowing to extend attributes via inheritance would lead to too much confusing situations. For this use case one could use the |
Agreed on this, didn't think about that. But yes, when adding any property (or whatever) to the extended class then the handling "of Symfony" doesn't understand it anyway.
I'm unfamiliar with that attribute. But after giving it a quick glance I don't think that's a solution? It would only allow me to configure an interface for autoconfiguration (with a tag), so it's not an attribute, nor contains some default configuration. And on top of that using So I'll just have to copy paste By the way: doesn't your argument against this (and preferring making |
Each attributes are handled differently.
There's no one-size-fits-all reasoning. Maybe registerAttributeForAutoconfiguration could be made to work by "instanceof" - or maybe there are valid reasons to have it as is. I don't remember. What @chalasr describes is still accurate today so if you'd like things to be otherwise, I invite you to have a look at the code and see what could be done about it. This would be for another issue - not directly related to AsMessageHandler, so this issue if fine closed now. |
Thinking twice about this, I think the current behavior is legit. Unlike Autowire/Autoconfigure, registerAttributeForAutoconfiguration provides a way to read extra properties. The former don't so they can be inherited without loosing any semantics. |
This actually is only "halve" the truth. symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php Lines 670 to 679 in a3686fb
In other words: any extra properties one could add to an extended #[AsMessageHandler] would actually just be set as attributes on the tag. So extending AsMessageHandler and adding a public string $foo to it would map to a 'foo' => ... tag attribute. But obviously if one really needs additional logic based on additional attributes that wouldn't work. But at the same time: shouldn't such additional attributes be handled in a compiler pass anyway? Because a tag (and it's attributes) on it's own don't do anything and don't add any logic / behavior. It's the compiler pass which acts on the tag (and optional attributes) to configure the container.
Agreed that it would be a generic implementation. But at the same time adding it needs a use case. I guess that creating a PR to change the workings of
I'm not sure I understand what you mean. IMO, also based on above comment (any properties being mapped to tag attributes), it would make more sense that |
…child classes (GromNaN) This PR was squashed before being merged into the 7.1 branch. Discussion ---------- [DependencyInjection] Apply attribute configurator to child classes | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix #52898 | License | MIT This allows extending attribute classes registered for autoconfiguration. Use-case: Share configuration between several classes with pre-configured attribute classes. As described in #52898 (bus name for `AsMessageHandler`, schedule name for `AsCronTask` and `AsPeriodicTask`) The child-class attribute is handled by the same function as it's parent class that is registered for autoconfiguration. This means any additional property will be ignored (unless supported, which could be new feature for the `AsTaggedItem` attribute configurator). If there is a configurator for the child class, the configurator for the parent class is not called. Commits ------- 69dc71b [DependencyInjection] Apply attribute configurator to child classes
Thank you for this @GromNaN 🎉 Also good to see (in the PR) that Symfony itself can already make use of it, with the workflow listeners. (And thanks for the ping as well, wouldn't have noticed it otherwise I guess :)) |
Description
The
AsMessageHandler
attribute has some options which would be pretty common / supplied by numerous locations using the attribute. For example the$bus
argument, if you define multiple buses you would most likely want to define this argument for all (or all except one, the default, bus type). Being able to extend theAsMessageHandler
would make this a lot simpler.Currently one can actually extend the class. But this doesn't work as the
AttributeAutoconfigurationPass
doesn't handle inheritance. Something which it IMO also shouldn't do by default. But in some cases there are attribute where it really makes sense to allow inheritance.In case this wouldn't be accepted, it is my opinion that the attribute class, i.e.
AsMessageHandler
should befinal
, as extending it actually doesn't work / extending it only has the meaning of inheriting the properties, but not the behavior (autoconfiguration) applied to the attribute.Example
in combination with
Instead of the current:
(obviously having multiple
As...Handler
attributes which use different$bus
arguments)The text was updated successfully, but these errors were encountered: