Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
HypeMC wants to merge1 commit intosymfony:7.4fromHypeMC:without-inheritance

Conversation

@HypeMC
Copy link
Member

@HypeMCHypeMC commentedAug 25, 2025
edited
Loading

QA
Branch?7.4
Bug fix?no
New feature?yes
Deprecations?no
Issues-
LicenseMIT

When configuring services like normalizers for a named serializer or Monolog processors for specific channels/handlers, autoconfiguration can get in the way.

For example, theNormalizerInterface isregistered 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 MyNormalizerimplements NormalizerInterface {}

Currently, the only way around this is to disable autoconfiguration entirely:

services:App\MyNormalizer:autoconfigure:falsetags:            -serializer.normalizer:{ serializer: 'my_named_serializer' }

This PR introduces a newinherit_configuration option for service definitions and a#[WithoutInheritedConfiguration] attribute.
Both allow skipping the inheritance ofinstanceof conditionals from parent classes or interfaces:

#[AutoconfigureTag(    name:'serializer.normalizer',    attributes: ['serializer' =>'my_named_serializer',    ],)]#[WithoutInheritedConfiguration]class MyNormalizerimplements NormalizerInterface {}

It can also be used to exclude specific services from inheriting_instanceof configurations:

services:_defaults:autowire:trueautoconfigure:true_instanceof:App\SomeInterface:tags:['some.tag']App\SomeInterfaceImplementation:inherit_configuration:false# This implementation won't inherit instanceof config

Why a new attribute?

I initially tried adding a new argument to the existing#[Autoconfigure] attribute.
However, this attribute itself isresolved via instanceof conditionals.
I could try something like$conditionals[$class], but since the attribute is repeatable, it’s unclear how to handle cases like:

#[Autoconfigure(inheritConfiguration:false)]#[Autoconfigure(inheritConfiguration:true)]class MyClass {}

@nicolas-grekas
Copy link
Member

Thanks for the detailed description.
I'd prefer not adding this, because it means more exceptions to the rules of autoconfiguration.
But I do understand why it might be needed :)

Before, let me challenge the proposal:

  • What about not ignoring a serializer.normalizer tag with no name when another one exists with a name? that'd be something to deal with in the compiler pass
  • Please expand on Monolog channels/handlers so that we can wonder about similar more specific rules?

@HypeMC
Copy link
MemberAuthor

HypeMC commentedAug 25, 2025
edited
Loading

@nicolas-grekas Hi. Yeah, I see your point about exceptions. I'm not sure how many cases like this there actually are.

What about not ignoring aserializer.normalizer tag with no name when another one exists with a name? that'd be something to deal with in the compiler pass

I'm assuming you meantignore 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.

Please expand on Monolog channels/handlers so that we can wonder about similar more specific rules?

Here's a simple example:

#[AsMonologProcessor('my_channel')]finalclass MyProcessorimplements ProcessorInterface{publicfunction__invoke(LogRecord$record) {}}

You'd expect this processor to be registered only formy_channel, but becauseProcessorInterface isregistered for autoconfiguration, the processor is added to all channels.

The workaround is the same, disable autoconfiguration and add an explicit tag.

services:App\MyProcessor:autoconfigure:falsetags:            -monolog.processor:{ channel: 'my_channel' }

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedAug 25, 2025
edited
Loading

I'd like to see how my proposal fits before looking for a more generic solution, to lower the overall complexity of things...

HypeMC reacted with thumbs up emoji

@HypeMC
Copy link
MemberAuthor

@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.

fabpot added a commit that referenced this pull requestAug 26, 2025
…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       | MITAn alternative to#61511.Commits-------e442a38 [Serializer] Don't fallback to default serializer if tags specify a named one
@fabpot
Copy link
Member

Closing in favor of#61526

@fabpotfabpot closed thisAug 26, 2025
@HypeMCHypeMC deleted the without-inheritance branchAugust 26, 2025 07:16
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

7.4

Development

Successfully merging this pull request may close these issues.

4 participants

@HypeMC@nicolas-grekas@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp