-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Console] Add support for method-based commands #62567
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
base: 8.1
Are you sure you want to change the base?
Conversation
9eaaeca to
8e4f9a0
Compare
|
better review hiding whitespace https://github.com/symfony/symfony/pull/62567/files?w=1 |
8e4f9a0 to
74eac25
Compare
|
how does this interact with the |
|
To me, the component standalone usage should show how to register those in an Application actually (which will probably show that those are much more cumbersome to use than the invokable commands by having to do the |
when the |
| private function registerCommand(ContainerBuilder $container, \ReflectionClass $reflection, string $id, string $class, array $tags, Definition $definition, array &$serviceIds, array &$lazyCommandMap, array &$lazyCommandRefs): void | ||
| { | ||
| if (!$reflection->isSubclassOf(Command::class)) { | ||
| $method = $tags[0]['method'] ?? '__invoke'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reading $tags[0] is broken when processing the registration for other tags. It will not validate the right method (and won't register the right one either)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the broken escenario. other tags for the same command method will be processed later and interpreted as aliases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, tags are now split into methods, so there is no way to process other tags with a different method in this same iteration
src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php
Outdated
Show resolved
Hide resolved
This is a bad advice because the Application class supports resolving commands using any non-ambiguous shortened name passed as the |
b84cd82 to
e123736
Compare
yes, that's unfortunately not perfect, so I've added support for injecting the #[Interact]
public function prompt(Command $cmd, /* ... */): void
{
// $cmd->getName()
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does this interact with the Prompt attribute added in version 7.4 ?
when the
#[Interact]attribute is used, it will need to check$input->getArgument('command')to distinguish the executed command. we can create as many#[Interact]as needed. though this new approach shouldn't be used for complex commands
Calling all the #[Interact] methods of the class for every commands is the most logical behavior. This feature will only be usable when all the command methods have the same interaction needs.
src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php
Outdated
Show resolved
Hide resolved
e123736 to
cb1d853
Compare
| if (isset($tag['method'])) { | ||
| $commandServices[$id][$tag['method']][] = $tag; | ||
| } else { | ||
| $commandServices[$id]['__invoke'][] = $tag; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This way, it is more obvious that these two lines do the same thing with a default value.
| if (isset($tag['method'])) { | |
| $commandServices[$id][$tag['method']][] = $tag; | |
| } else { | |
| $commandServices[$id]['__invoke'][] = $tag; | |
| } | |
| $commandServices[$id][$tag['method'] ?? '__invoke'][] = $tag; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually had the opposite view 😅 but I'm fine with your suggestion if others prefer it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your review 🙏
Same as with Controllers and Messenger Handlers, this would allow defining multiple commands in the same class:
Asked by @kbond in #59340 (review)
Component standalone usage:
Testing: