[Console] Add support for method-based commands#62567
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.
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.
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.
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.
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
src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php
Show resolved
Hide resolved
cb1d853 to
8bfc423
Compare
8bfc423 to
6b3ebfb
Compare
|
Thank you @yceruto. |
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: