-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
default_index_method
no longer works with contiguous integers since 7.0
#60651
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
default_index_method
no longer works in 7.2
@Bilge At first glance, your service definition seems to be incorrect. It should be: _instanceof:
Org\AbstractUnpacker:
tags:
- unpacker I've tested it, and it seems to work as expected. Here's the dumped container: public static function do($container, $lazyLoad = true)
{
include_once \dirname(__DIR__, 4).'/src/Unpacker/Unpacker.php';
return $container->privates['App\\Unpacker\\Unpacker'] = new \App\Unpacker\Unpacker(new \Symfony\Component\DependencyInjection\Argument\ServiceLocator($container->getService ??= $container->getService(...), [
10 => ['privates', 'App\\Unpacker\\BarUnpacker', 'getBarUnpackerService', true],
5 => ['privates', 'App\\Unpacker\\FooUnpacker', 'getFooUnpackerService', true],
], [
10 => 'App\\Unpacker\\BarUnpacker',
5 => 'App\\Unpacker\\FooUnpacker',
]));
} Could you create a small example application to reproduce your issue? |
I am glad it works for you but clearly it does not (any longer) for me. public static function do($container, $lazyLoad = true)
{
include_once \dirname(__DIR__, 4).'/src/CrankingService.php';
if (isset($container->privates['Org\\CrankingService'])) {
return $container->privates['Org\\CrankingService'];
}
return $container->privates['Org\\CrankingService'] = new Org\CrankingService(new \Symfony\Component\DependencyInjection\Argument\ServiceLocator($container->getService ??= $container->getService(...), [
'Org\\UnpackerV0' => ['privates', 'Org\\UnpackerV0', 'getUnpackerV0Service', true],
'Org\\UnpackerV1' => ['privates', 'Org\\UnpackerV1', 'getUnpackerV1Service', true],
], [
'Org\\UnpackerV0' => 'Org\\UnpackerV0',
'Org\\UnpackerV1' => 'Org\\UnpackerV1',
]));
} Since you already produced a small example to test it, perhaps you could share that so I can see what you've done differently (and modify if needs be)? I notice you're using non-contiguous numbering (10, 5) rather than (0, 1). Perhaps there is code somewhere that checks if it looks like a list and does something different... |
@Bilge Here you go: 7.2-default-index-method.zip. There's a
Not sure, could you perhaps test that case? |
I don't know how you can claim it "works". Without making any changes whatsoever to the test application you provided, running the command you included fails with: ❯ bin/console app:test -v
This is exactly the problem I was posting about, so again, not sure how it works for you (but thanks for the reproducer). |
@Bilge Ok, so now I'm confused, did you change anything on your side? $ bin/console app:test
1 App\Unpacker\FooUnpacker {#248}
2 App\Unpacker\BarUnpacker {#331} |
@Bilge Which PHP version are you using? |
For the above test:
For the original report:
|
@HypeMC it indeed is caused by the indexes making the references a list..! symfony/src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php Lines 113 to 137 in c1d73b1
|
Looks like the change comes from #50578 which slightly modified the |
default_index_method
no longer works in 7.2default_index_method
no longer works with contiguous integers since 7.0
…handling (MatTheCat) This PR was merged into the 7.2 branch. Discussion ---------- [DependencyInjection] Fix `ServiceLocatorTagPass` indexes handling | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #60651 | License | MIT #50578 changed the `ServiceLocatorTagPass`’ behavior so that if the map is a list, its indexes always are replaced by the corresponding reference ID, even if they come from the `PriorityTaggedServiceTrait`. That means if your service map ends up as a list because e.g. your `default_index_method` returned contiguous integer, its indexes will be replaced. This PR reverts this change so that it works the same than v6. Commits ------- a73c9d1 [DependencyInjection] Fix `ServiceLocatorTagPass` indexes handling
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected
7.2.7
Description
Worked fine in 6.4, but now it seems to be completely ignored in 7.x. The tagged locator just uses the class name as the key now, ignoring the value returned by
default_index_method
, despite the fact that the method is still called at container compile time. In case it matters, my index method returns inint
.How to reproduce
Tag some services.
Inject services.
Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: