Skip to content

Commit 4e677eb

Browse files
feature #60910 [DependencyInjection] Add argument $target to ContainerBuilder::registerAliasForArgument() (nicolas-grekas)
This PR was merged into the 7.4 branch. Discussion ---------- [DependencyInjection] Add argument `$target` to `ContainerBuilder::registerAliasForArgument()` | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT This makes the API simpler and fixes `debug:autowiring`, which now displays e.g.: ``` Symfony\Component\Workflow\WorkflowInterface $commentStateMachine - target:comment - alias:state_machine.comment ``` Commits ------- 8b79ff5d8a3 [DependencyInjection] Add argument `$target` to `ContainerBuilder::registerAliasForArgument()`
2 parents 97b31fc + fc250ed commit 4e677eb

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

Command/DebugAutowiringCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
137137
}
138138
$target = substr($id, \strlen($previousId) + 3);
139139

140-
if ($previousId.' $'.(new Target($target))->getParsedName() === $serviceId) {
140+
if ($container->findDefinition($id) === $container->findDefinition($serviceId)) {
141141
$serviceLine .= ' - <fg=magenta>target:</><fg=cyan>'.$target.'</>';
142142
break;
143143
}

DependencyInjection/FrameworkExtension.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,8 +1190,7 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
11901190
// Store to container
11911191
$container->setDefinition($workflowId, $workflowDefinition);
11921192
$container->setDefinition($definitionDefinitionId, $definitionDefinition);
1193-
$container->registerAliasForArgument($workflowId, WorkflowInterface::class, $name.'.'.$type);
1194-
$container->registerAliasForArgument($workflowId, WorkflowInterface::class, $name);
1193+
$container->registerAliasForArgument($workflowId, WorkflowInterface::class, $name.'.'.$type, $name);
11951194

11961195
// Add workflow to Registry
11971196
if ($workflow['supports']) {
@@ -1426,8 +1425,7 @@ private function registerAssetsConfiguration(array $config, ContainerBuilder $co
14261425
$packageDefinition = $this->createPackageDefinition($package['base_path'], $package['base_urls'], $version)
14271426
->addTag('assets.package', ['package' => $name]);
14281427
$container->setDefinition('assets._package_'.$name, $packageDefinition);
1429-
$container->registerAliasForArgument('assets._package_'.$name, PackageInterface::class, $name.'.package');
1430-
$container->registerAliasForArgument('assets._package_'.$name, PackageInterface::class, $name);
1428+
$container->registerAliasForArgument('assets._package_'.$name, PackageInterface::class, $name.'.package', $name);
14311429
}
14321430
}
14331431

@@ -2248,8 +2246,7 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
22482246
$container->setAlias('lock.factory', new Alias('lock.'.$resourceName.'.factory', false));
22492247
$container->setAlias(LockFactory::class, new Alias('lock.factory', false));
22502248
} else {
2251-
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactory::class, $resourceName.'.lock.factory');
2252-
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactory::class, $resourceName);
2249+
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactory::class, $resourceName.'.lock.factory', $resourceName);
22532250
}
22542251
}
22552252
}
@@ -2284,8 +2281,7 @@ private function registerSemaphoreConfiguration(array $config, ContainerBuilder
22842281
$container->setAlias('semaphore.factory', new Alias('semaphore.'.$resourceName.'.factory', false));
22852282
$container->setAlias(SemaphoreFactory::class, new Alias('semaphore.factory', false));
22862283
} else {
2287-
$container->registerAliasForArgument('semaphore.'.$resourceName.'.factory', SemaphoreFactory::class, $resourceName.'.semaphore.factory');
2288-
$container->registerAliasForArgument('semaphore.'.$resourceName.'.factory', SemaphoreFactory::class, $resourceName);
2284+
$container->registerAliasForArgument('semaphore.'.$resourceName.'.factory', SemaphoreFactory::class, $resourceName.'.semaphore.factory', $resourceName);
22892285
}
22902286
}
22912287
}
@@ -3310,13 +3306,11 @@ private function registerRateLimiterConfiguration(array $config, ContainerBuilde
33103306
$factoryAlias = $container->registerAliasForArgument($limiterId, RateLimiterFactory::class, $name.'.limiter');
33113307

33123308
if (interface_exists(RateLimiterFactoryInterface::class)) {
3313-
$container->registerAliasForArgument($limiterId, RateLimiterFactoryInterface::class, $name.'.limiter');
3314-
$factoryAlias->setDeprecated('symfony/framework-bundle', '7.3', \sprintf('The "%%alias_id%%" autowiring alias is deprecated and will be removed in 8.0, use "%s $%s" instead.', RateLimiterFactoryInterface::class, (new Target($name.'.limiter'))->getParsedName()));
3315-
$internalAliasId = \sprintf('.%s $%s.limiter', RateLimiterFactory::class, $name);
3309+
$container->registerAliasForArgument($limiterId, RateLimiterFactoryInterface::class, $name.'.limiter', $name);
33163310

3317-
if ($container->hasAlias($internalAliasId)) {
3318-
$container->getAlias($internalAliasId)->setDeprecated('symfony/framework-bundle', '7.3', \sprintf('The "%%alias_id%%" autowiring alias is deprecated and will be removed in 8.0, use "%s $%s" instead.', RateLimiterFactoryInterface::class, (new Target($name.'.limiter'))->getParsedName()));
3319-
}
3311+
$factoryAlias->setDeprecated('symfony/framework-bundle', '7.3', 'The "%alias_id%" autowiring alias is deprecated and will be removed in 8.0, use "RateLimiterFactoryInterface" instead.');
3312+
$container->getAlias(\sprintf('.%s $%s.limiter', RateLimiterFactory::class, $name))
3313+
->setDeprecated('symfony/framework-bundle', '7.3', 'The "%alias_id%" autowiring alias is deprecated and will be removed in 8.0, use "RateLimiterFactoryInterface" instead.');
33203314
}
33213315
}
33223316

@@ -3341,7 +3335,7 @@ private function registerRateLimiterConfiguration(array $config, ContainerBuilde
33413335
)))
33423336
;
33433337

3344-
$container->registerAliasForArgument($limiterId, RateLimiterFactoryInterface::class, $name.'.limiter');
3338+
$container->registerAliasForArgument($limiterId, RateLimiterFactoryInterface::class, $name.'.limiter', $name);
33453339
}
33463340
}
33473341

0 commit comments

Comments
 (0)