Skip to content

fix(bundle): alias the nested token services with their own class - #673

Open
Spomky wants to merge 1 commit into
4.1.xfrom
fix/bundle-autowiring-aliases
Open

fix(bundle): alias the nested token services with their own class#673
Spomky wants to merge 1 commit into
4.1.xfrom
fix/bundle-autowiring-aliases

Conversation

@Spomky

@Spomky Spomky commented Aug 6, 2026

Copy link
Copy Markdown
Member

Fixes #660.

NestedTokenBuilder and NestedTokenLoader (the DI sources) registered their autowiring alias against self::class — the class of the configuration source — instead of the class of the service they create. The resulting aliases were:

Jose\Bundle\JoseFramework\DependencyInjection\Source\NestedToken\NestedTokenLoader $nestedTokenLoader1NestedTokenLoader

Nothing could ever resolve them, so autowiring a nested token loader or builder failed. They now read:

Jose\Component\NestedToken\NestedTokenLoader $nestedTokenLoader1NestedTokenLoader
Jose\Component\NestedToken\NestedTokenBuilder $nestedTokenBuilder1NestedTokenBuilder

The naming convention (<config name> + service kind) is unchanged, and it matches every other source ($jwsLoader1JwsLoader, $builder1JweBuilder, …).

Are the others affected?

No. I went through all 14 registerAliasForArgument() call sites: the twelve others pass the class of the service, and AbstractSource passes $definition->getClass(). Only the two nested token ones were wrong.

To keep it that way, AutowiringAliasesTest loads the bundle extension with the functional test configuration, walks every autowiring alias it registers, and asserts the aliased service is an instance of the aliased type. That covers 22 aliases across all sources today and picks up any new one automatically. It fails on both nested token aliases without the fix.

NestedTokenServiceConsumer in the test bundle reproduces the report end to end: it takes both services through autowiring only, and the two new functional tests check it receives the services from the configuration.

Not addressed here

The $target argument of registerAliasForArgument(), suggested in the issue's additional context, would let people write #[Target('nested_token_loader_1')] instead of the suffixed name. It landed in Symfony 7.4 and this branch supports symfony/dependency-injection: ^7.0|^8.0, so it can't be used unconditionally here. Worth a separate issue on a branch that can raise the requirement — it applies to every source, not just these two.

Test run

Full suite: 777 tests, 38 failures — the same 38 that fail on an untouched 4.1.x checkout. They are all *ConfigurationTest cases where matthiasnoback/symfony-config-test no longer matches the Symfony 8.1 config error messages, unrelated to this change. ECS and PHPStan cannot run on 4.1.x at all (broken tool configuration, already repaired on 4.2.x by #669).

The nested token sources registered their autowiring alias against the
class of the configuration source itself instead of the class of the
service they create, so nothing could ever be autowired through
`Jose\Component\NestedToken\NestedTokenLoader $<name>NestedTokenLoader`
or its builder counterpart.

A test walks every autowiring alias the bundle registers and checks that
the aliased service is an instance of the aliased type, so the twelve
other sources are covered as well.
@Spomky Spomky linked an issue Aug 6, 2026 that may be closed by this pull request
@Spomky Spomky added this to the 4.1.9 milestone Aug 6, 2026
@Spomky Spomky self-assigned this Aug 6, 2026
@Spomky Spomky added the bug label Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autowiring aliases defined by the bundle are wrong

1 participant