Skip to content

[FrameworkBundle] Allow using their name without added suffix when using #[Target] for custom services #60874

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
7.4
---

* Allow using their name without added suffix when using `#[Target]` for custom services
Copy link
Contributor

@mttsch mttsch Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I alone in having a problem properly understanding this line? (May-be its the "their" being used before its clear what it is referencing?)

Copy link
Contributor Author

@Valmonzo Valmonzo Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imagine you have some services like a LockFactory named foo, before the target worked like #[Target('foo.lock.factory)] LockFactory $lockFactory, now you can use #[Target('foo')] LockFactory $lockFactory

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But from the code diff, this only applies to the concrete services, for which you added suffix-less aliases? Is it really tightly coupled to #[Target] in general, or just for specific services and wouldn't these aliases also work in services.yaml, for example?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard also for me!

* Deprecate `Symfony\Bundle\FrameworkBundle\Console\Application::add()` in favor of `Symfony\Bundle\FrameworkBundle\Console\Application::addCommand()`
* Add `assertEmailAddressNotContains()` to the `MailerAssertionsTrait`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,7 @@ private function registerAssetsConfiguration(array $config, ContainerBuilder $co
->addTag('assets.package', ['package' => $name]);
$container->setDefinition('assets._package_'.$name, $packageDefinition);
$container->registerAliasForArgument('assets._package_'.$name, PackageInterface::class, $name.'.package');
$container->registerAliasForArgument('assets._package_'.$name, PackageInterface::class, $name);
}
}

Expand Down Expand Up @@ -2247,6 +2248,7 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
$container->setAlias(LockFactory::class, new Alias('lock.factory', false));
} else {
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactory::class, $resourceName.'.lock.factory');
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactory::class, $resourceName);
}
}
}
Expand Down Expand Up @@ -2282,6 +2284,7 @@ private function registerSemaphoreConfiguration(array $config, ContainerBuilder
$container->setAlias(SemaphoreFactory::class, new Alias('semaphore.factory', false));
} else {
$container->registerAliasForArgument('semaphore.'.$resourceName.'.factory', SemaphoreFactory::class, $resourceName.'.semaphore.factory');
$container->registerAliasForArgument('semaphore.'.$resourceName.'.factory', SemaphoreFactory::class, $resourceName);
}
}
}
Expand Down Expand Up @@ -3307,7 +3310,8 @@ private function registerRateLimiterConfiguration(array $config, ContainerBuilde

if (interface_exists(RateLimiterFactoryInterface::class)) {
$container->registerAliasForArgument($limiterId, RateLimiterFactoryInterface::class, $name.'.limiter');
$factoryAlias->setDeprecated('symfony/dependency-injection', '7.3', 'The "%alias_id%" autowiring alias is deprecated and will be removed in 8.0, use "RateLimiterFactoryInterface" instead.');
$container->registerAliasForArgument($limiterId, RateLimiterFactoryInterface::class, $name);
$factoryAlias->setDeprecated('symfony/framework-bundle', '7.3', 'The "%alias_id%" autowiring alias is deprecated and will be removed in 8.0, use "RateLimiterFactoryInterface" instead.');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Symfony\Component\HttpFoundation\RateLimiter\RequestRateLimiterInterface;
use Symfony\Component\Lock\LockInterface;
use Symfony\Component\RateLimiter\RateLimiterFactory;
use Symfony\Component\RateLimiter\RateLimiterFactoryInterface;
use Symfony\Component\RateLimiter\Storage\CacheStorage;
use Symfony\Component\Security\Http\RateLimiter\DefaultLoginRateLimiter;

Expand Down Expand Up @@ -115,6 +116,12 @@ private function registerRateLimiter(ContainerBuilder $container, string $name,
$limiterConfig['id'] = $name;
$limiter->replaceArgument(0, $limiterConfig);

$container->registerAliasForArgument($limiterId, RateLimiterFactory::class, $name.'.limiter');
$factoryAlias = $container->registerAliasForArgument($limiterId, RateLimiterFactory::class, $name.'.limiter');

if (interface_exists(RateLimiterFactoryInterface::class)) {
$container->registerAliasForArgument($limiterId, RateLimiterFactoryInterface::class, $name.'.limiter');
$container->registerAliasForArgument($limiterId, RateLimiterFactoryInterface::class, $name);
$factoryAlias->setDeprecated('symfony/security-bundle', '7.4', 'The "%alias_id%" autowiring alias is deprecated and will be removed in 8.0, use "RateLimiterFactoryInterface" instead.');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ private function configureNamedSerializers(ContainerBuilder $container, ?string

$container->registerChild($serializerId, 'serializer')->setArgument('$defaultContext', $config['default_context']);
$container->registerAliasForArgument($serializerId, SerializerInterface::class, $serializerName.'.serializer');
$container->registerAliasForArgument($serializerId, SerializerInterface::class, $serializerName);
$container->registerAliasForArgument($serializerId, NormalizerInterface::class, $serializerName.'.normalizer');
$container->registerAliasForArgument($serializerId, NormalizerInterface::class, $serializerName);
$container->registerAliasForArgument($serializerId, DenormalizerInterface::class, $serializerName.'.denormalizer');
$container->registerAliasForArgument($serializerId, DenormalizerInterface::class, $serializerName);

$this->configureSerializer($container, $serializerId, $normalizers, $encoders, $serializerName);

Expand Down
Loading