Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 965283a

Browse files
committed
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()`
2 parents 7e4f02e + b5ab0e3 commit 965283a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Symfony/Component/Console/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.1
5+
---
6+
7+
* Add `ArgvInput::getRawTokens()`
8+
49
7.0
510
---
611

src/Symfony/Component/Console/Input/ArgvInput.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,16 @@ public function getParameterOption(string|array $values, string|bool|int|float|a
345345
return $default;
346346
}
347347

348+
/**
349+
* Returns un-parsed and not validated tokens.
350+
*
351+
* @return list<string>
352+
*/
353+
public function getRawTokens(): array
354+
{
355+
return $this->tokens;
356+
}
357+
348358
/**
349359
* Returns a stringified representation of the args passed to the command.
350360
*/

0 commit comments

Comments
 (0)