-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[DependencyInjection] Allow disabling instanceof config inheritance #61511
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
Conversation
ddf1359 to
3fb5849
Compare
|
Thanks for the detailed description. Before, let me challenge the proposal:
|
|
@nicolas-grekas Hi. Yeah, I see your point about exceptions. I'm not sure how many cases like this there actually are.
I'm assuming you meant ignore the one without a name. I agree, that would solve the serializer case. However, there might be other cases besides this and the Monolog one.
Here's a simple example: #[AsMonologProcessor('my_channel')]
final class MyProcessor implements ProcessorInterface
{
public function __invoke(LogRecord $record) {}
}You'd expect this processor to be registered only for The workaround is the same, disable autoconfiguration and add an explicit tag. services:
App\MyProcessor:
autoconfigure: false
tags:
- monolog.processor: { channel: 'my_channel' } |
|
I'd like to see how my proposal fits before looking for a more generic solution, to lower the overall complexity of things... |
|
@nicolas-grekas Please see #61526. I've opened it as a bug fix cause it seems like one, if need I'll switch to 7.4. |
…specify a named one (HypeMC) This PR was merged into the 7.3 branch. Discussion ---------- [Serializer] Don't fallback to default serializer if tags specify a named one | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT An alternative to #61511. Commits ------- e442a38 [Serializer] Don't fallback to default serializer if tags specify a named one
|
Closing in favor of #61526 |
When configuring services like normalizers for a named serializer or Monolog processors for specific channels/handlers, autoconfiguration can get in the way.
For example, the
NormalizerInterfaceis registered for autoconfiguration.If I try to register a custom normalizer for a specific named serializer, it also gets registered with the default serializer because of autoconfiguration:
#[AutoconfigureTag( name: 'serializer.normalizer', attributes: [ 'serializer' => 'my_named_serializer', ], )] class MyNormalizer implements NormalizerInterface {}Currently, the only way around this is to disable autoconfiguration entirely:
This PR introduces a new
inherit_configurationoption for service definitions and a#[WithoutInheritedConfiguration]attribute.Both allow skipping the inheritance of
instanceofconditionals from parent classes or interfaces:#[AutoconfigureTag( name: 'serializer.normalizer', attributes: [ 'serializer' => 'my_named_serializer', ], )] #[WithoutInheritedConfiguration] class MyNormalizer implements NormalizerInterface {}It can also be used to exclude specific services from inheriting
_instanceofconfigurations:Why a new attribute?
I initially tried adding a new argument to the existing
#[Autoconfigure]attribute.However, this attribute itself is resolved via instanceof conditionals.
I could try something like
$conditionals[$class], but since the attribute is repeatable, it’s unclear how to handle cases like: