Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Lock] [Framework] Add private aliases with only name for LockFactory 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

Open
wants to merge 2 commits into
base: 7.4
Choose a base branch
from

Conversation

Valmonzo
Copy link
Contributor

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #60349
License MIT

@carsonbot carsonbot added this to the 7.4 milestone Jun 23, 2025
@carsonbot carsonbot changed the title [Lock][Framework] Add private aliases for LockFactory services [Lock] [Framework] Add private aliases for LockFactory services Jun 23, 2025
@Valmonzo Valmonzo changed the title [Lock] [Framework] Add private aliases for LockFactory services [Lock] [Framework] Add private aliases with only name for LockFactory services Jun 23, 2025
nicolas-grekas

This comment was marked as duplicate.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Workflow works because it has two lines:

$container->registerAliasForArgument($workflowId, WorkflowInterface::class, $name.'.'.$type);
$container->registerAliasForArgument($workflowId, WorkflowInterface::class, $name);

HttpClient/Cache work because they don't add any conventions: scoped clients' / cache pool names are their service names.

And there are other subsystems that create their own conventions:

$container->registerAliasForArgument($serializerId, SerializerInterface::class, $serializerName.'.serializer');
$container->registerAliasForArgument($serializerId, NormalizerInterface::class, $serializerName.'.normalizer');
$container->registerAliasForArgument($serializerId, DenormalizerInterface::class, $serializerName.'.denormalizer');
$container->registerAliasForArgument('assets._package_'.$name, PackageInterface::class, $name.'.package');
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactory::class, $resourceName.'.lock.factory');
$container->registerAliasForArgument('semaphore.'.$resourceName.'.factory', SemaphoreFactory::class, $resourceName.'.semaphore.factory');
$container->registerAliasForArgument($limiterId, RateLimiterFactoryInterface::class, $name.'.limiter');

Looks like they would all benefit from something similar, isn't it?

To improve the situation, we could add an argument, $target to registerAliasForArgument (using a proper BC layer). The implementation would just create this second alias we're considering to add here.
And we would also patch debug:autowiring so that it groups those two lines in one (see "target" entry in the output).

WDYT?
Is this something you might want to work on @Valmonzo?

@stof
Copy link
Member

stof commented Jun 23, 2025

@nicolas-grekas most cases are adding a suffix mostly because they were implemented at a time where named autowiring was based on argument names, where we would expect the argument name (and so often the property name) to end with normalizer if it is a NormalizerInterface for instance.

When using the Target attribute, using the original name directly is much better (personally, I would even vote for deprecating parameter-name based named autowiring in favor of the attribute which fails clearly for invalid targets thanks to explicit intent)

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jun 23, 2025

So let's start with adding all those aliases and call registerAliasForArgument()->setDeprecated('symfony/the-bundle', '7.4', \sprintf('Using "%%alias_id%%" to get a named service is deprecated, use #[Target('%s')] on the arguments instead.', $name)) for them all?

@stof
Copy link
Member

stof commented Jun 23, 2025

@nicolas-grekas given the maintenance cost of the double aliases is low, maybe we should make it easier to support multiple versions of Symfony by delaying the deprecation (you cannot use #[Target('foo') when supporting 7.3 or 6.4 as the alias using the unsuffixed target is not there). and adding a conditional attribute depending on the version of FrameworkBundle is not possible.

@chalasr
Copy link
Member

chalasr commented Jun 23, 2025

I like the fact that one can choose not to use the attribute as it’s less boilerplate for aliases that are used a lot.

@Valmonzo
Copy link
Contributor Author

Same preference as @chalasr , but whatever you choose, I'll be happy to work on it !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lock] Renamed target for autowire
5 participants