-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Events and InputDefinition problematic #10695
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
Comments
+:100:, especially for the 1st bullet point. In my case, we need to check if an option exists, if it has a value, and then feed another object (a bag) if it has a valid value. But, I think I'm gonna need to do the workaround @Tobion is describing (the A solution would be to maybe fire another event, which is fired after the input is bound ? |
👍 I noticed your issue after writing mine here #11912 |
+1. The arguments are not compiled until $command->run() is executed. The argument parsing should happen prior to the run. Additionally, to not introduce breaking changes, we could possibly add a new Event that happens after parsing them, so that the COMMAND event still happens before parsing. |
…t (WouterJ) This PR was merged into the 2.8 branch. Discussion ---------- [Console] Bind input before executing the COMMAND event | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10695 (problem 1) | License | MIT | Doc PR | - Previously, `$input` wasn't very usefull in the `console.command` event, as the input was not yet bound to the command definition. With this PR, the input is now bound twice: Once before the event is dispatched (to make it usefull in the listeners) and once at the original location in `Command#run()` (to allow changing the input definition in an event listener). Commits ------- 0af1676 Bind input before executing the COMMAND event
Closing this as the first main point has been fixed. I don't see a solution for the second one about the help. In theory the help could be different depending on arguments or any other runtime config. So there seems no generic way to adjust the help when a command is reconfigured using a listener. |
Thanks for having this fixed :) |
When listening to the console.command event and trying to access information there are some problems:
You cannot acess arguments or options in the InputInterface likeSolved by [Console] Bind input before executing the COMMAND event #15938$input->getOption('myoption');
because they are not parsed yet. It's done only later by the application.A workaround is something like
$command->mergeApplicationDefinition(); $input->bind($command->getDefinition());
inside your listener.IMO the input should already have to params bound before the listener. Otherwise the input is pretty useless in listeners. Since people might want to add arguments/options dynamically in a listener (see 2.), the definition probably also needs to be bound after the listener just as now. So it should be done before and after the listener automatically.
The text was updated successfully, but these errors were encountered: