Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #54238 [Console] Add
ArgvInput::getRawTokens()
(lyrixx)
This PR was merged into the 7.1 branch. Discussion ---------- [Console] Add `ArgvInput::getRawTokens()` | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT Many times, I had to access raw tokens, and each time I used reflection or other hacks to get theses values. So I think it's time to expose this property properly. For example, if you want to create a command that wrap a proces, with "pass thru" arguments, you need that. --- Examples: ```php #!/usr/bin/env php <?php use Symfony\Component\Console\SingleCommandApplication; use Symfony\Component\Process\Process; require __DIR__ . '/vendor/autoload.php'; $command = new SingleCommandApplication('ls'); $command->ignoreValidationErrors(); $command->setCode(function ($input) { $p = new Process(['ls', ...$input->getRawTokens()]); $p->setTty(true); $p->mustRun(); }); $command->run(); ``` ![image](https://github.com/symfony/symfony/assets/408368/d16d28ae-5aff-4df8-9978-216448bf1491) --- > [!NOTE] > In castor, we also strip all options until the command name > ```php > $parameters = []; > $keep = false; > foreach ($input->getRawTokens() as $value) { > if ($value === $input->getFirstArgument()) { > $keep = true; > > continue; > } > if ($keep) { > $parameters[] = $value; > } > } > ``` > It could be nice to add support for this too? Commits ------- b5ab0e3 [Console] Add `ArgvInput::getRawTokens()`
- Loading branch information