Skip to content

Commit 54f9d82

Browse files
[DependencyInjection] Add argument $target to ContainerBuilder::registerAliasForArgument()
1 parent 0d3fedf commit 54f9d82

File tree

6 files changed

+26
-27
lines changed

6 files changed

+26
-27
lines changed

UPGRADE-7.4.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Console
1313

1414
* Deprecate `Symfony\Component\Console\Application::add()` in favor of `Symfony\Component\Console\Application::addCommand()`
1515

16+
DependencyInjection
17+
-------------------
18+
19+
* Add argument `$target` to `ContainerBuilder::registerAliasForArgument()`
20+
1621
FrameworkBundle
1722
---------------
1823

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginThrottlingFactory.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,11 @@ private function registerRateLimiter(ContainerBuilder $container, string $name,
120120
$factoryAlias = $container->registerAliasForArgument($limiterId, RateLimiterFactory::class, $name.'.limiter');
121121

122122
if (interface_exists(RateLimiterFactoryInterface::class)) {
123-
$container->registerAliasForArgument($limiterId, RateLimiterFactoryInterface::class, $name.'.limiter');
124-
$container->registerAliasForArgument($limiterId, RateLimiterFactoryInterface::class, $name);
125-
$factoryAlias->setDeprecated('symfony/security-bundle', '7.4', \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()));
123+
$container->registerAliasForArgument($limiterId, RateLimiterFactoryInterface::class, $name.'.limiter', $name);
126124

127-
$internalAliasId = \sprintf('.%s $%s.limiter', RateLimiterFactory::class, $name);
128-
129-
if ($container->hasAlias($internalAliasId)) {
130-
$container->getAlias($internalAliasId)->setDeprecated('symfony/security-bundle', '7.4', \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()));
131-
}
125+
$factoryAlias->setDeprecated('symfony/security-bundle', '7.4', 'The "%alias_id%" autowiring alias is deprecated and will be removed in 8.0, use "RateLimiterFactoryInterface" instead.');
126+
$container->getAlias(\sprintf('.%s $%s.limiter', RateLimiterFactory::class, $name))
127+
->setDeprecated('symfony/security-bundle', '7.4', 'The "%alias_id%" autowiring alias is deprecated and will be removed in 8.0, use "RateLimiterFactoryInterface" instead.');
132128
}
133129
}
134130
}

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Allow `#[AsAlias]` to be extended
8+
* Add argument `$target` to `ContainerBuilder::registerAliasForArgument()`
89

910
7.3
1011
---

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,10 +1459,13 @@ public function registerAttributeForAutoconfiguration(string $attributeClass, ca
14591459
* using camel case: "foo.bar" or "foo_bar" creates an alias bound to
14601460
* "$fooBar"-named arguments with $type as type-hint. Such arguments will
14611461
* receive the service $id when autowiring is used.
1462+
*
1463+
* @param ?string $target
14621464
*/
1463-
public function registerAliasForArgument(string $id, string $type, ?string $name = null): Alias
1465+
public function registerAliasForArgument(string $id, string $type, ?string $name = null/*, ?string $target = null */): Alias
14641466
{
14651467
$parsedName = (new Target($name ??= $id))->getParsedName();
1468+
$target = (\func_num_args() > 3 ? func_get_arg(3) : null) ?? $name;
14661469

14671470
if (!preg_match('/^[a-zA-Z_\x7f-\xff]/', $parsedName)) {
14681471
if ($id !== $name) {
@@ -1472,8 +1475,8 @@ public function registerAliasForArgument(string $id, string $type, ?string $name
14721475
throw new InvalidArgumentException(\sprintf('Invalid argument name "%s"'.$id.': the first character must be a letter.', $name));
14731476
}
14741477

1475-
if ($parsedName !== $name) {
1476-
$this->setAlias('.'.$type.' $'.$name, $type.' $'.$parsedName);
1478+
if ($parsedName !== $target) {
1479+
$this->setAlias('.'.$type.' $'.$target, $type.' $'.$parsedName);
14771480
}
14781481

14791482
return $this->setAlias($type.' $'.$parsedName, $id);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy