[9.x] Improve input argument parsing for commands #44662
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed that whenever I would listen to the
CommandStarting
/CommandFinished
events, there was some functionality missing with theinput
property on this event (\Symfony\Component\Console\Input\InputInterface
). It appears that the input definition is not loaded at all and it causes thegetArguments()
/getOptions()
functions to be empty. So the following code would never work:Therefore I've added a few lines of code to
Illuminate\Console\Application
to load the input definition directly from the command that is being called. Thecatch
block around calling$input->bind()
appears to be a common thing judging by the occurrences in the Symfony codebase, I'm not sure why this is necessary.I've also just noticed by looking at this application structure, that Laravel is basically overriding some Symfony events (which DO work properly). Laravel calls its own
CommandStarting
/CommandFinished
events while there already is existing code in Symfony that uses their own (for instance https://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/Console/Application.php#L1006 and https://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/Console/Application.php#L1034). However, the Symfony commands cannot be listened to because there apparently is no event dispatcher attached in the Laravel override so these events are never sent.I'm not sure of the downsides of my addition so I've submitted this as a draft. Someone with more knowledge about the bootstrapping logic should have a look at this.