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
[Console] With AsCommand attribute setAliases() in configure() don't create the aliases #52650
Comments
The whole point of moving that to an attribute was to support lazy-loading commands to load only the command that is being run instead of all registered commands. This is indeed not compatible with configure the command dynamically. |
This is for example to allow you to make aliases for several cities in the database, for example: For example to filter Commands by city, permissions, etc. |
I still don't understand the use case: if you have 2 cities in the database and you add 2 aliases |
Depending on the city the script does a different treatment, for example city1:script load a configuration in database for city1 and city2 another configuration. |
@aleblanc how do you detect that ? |
With $input->getArgument('command') |
this won't be reliable. As Symfony supports shortening each part of the command name as much as you want as long as it is not ambiguous (meaning that there is only one command that has at least 1 name/alias that corresponds), you have no guarantee that the |
@stof says:
I fully agree. This is the right way for your use case. |
Yes, I also agree with @stof. Make city an argument and run
Does this mean we should remove the |
Not all usages of symfony/console are using a container with lazy-loaded commands. This method is still useful in standalone usages. |
I can see AsCommand attribute has |
@javaDeveloperKid the problem is dynamic aliases. |
Right. I missed it. |
In Application.php I can see there is a command loader which is a service locator. Maybe it could be decorated and the logic would be:
|
I agree the use case is better addressed otherwise, as mentioned above. |
Symfony version(s) affected
6.3
Description
In a Command symfony, with "AsCommand" attribute it's no longer possible to create dynamic alias in the configure() method (for exemple for create alias which comes from a database).
How to reproduce
php bin/console make:command
name it "app:demo"
Change configure like this (alias app:dynamic) :
Error : Command "app:dynamic" is not defined.
Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: