Skip to content

Commit e38e45b

Browse files
committed
minor symfony#19713 [Console] Mention ArgvInput::getRawTokens (alexandre-daubois)
This PR was merged into the 7.1 branch. Discussion ---------- [Console] Mention `ArgvInput::getRawTokens` Fix symfony#19693, symfony#19673 Commits ------- 7afdaa3 [Console] Mention `ArgvInput::getRawTokens`
2 parents 7b591e0 + 7afdaa3 commit e38e45b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

console/input.rst

+31
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,37 @@ The above code can be simplified as follows because ``false !== null``::
311311
$yell = ($optionValue !== false);
312312
$yellLouder = ($optionValue === 'louder');
313313

314+
Fetching The Raw Command Input
315+
------------------------------
316+
317+
Sometimes, you may need to fetch the raw input that was passed to the command.
318+
This is useful when you need to parse the input yourself or when you need to
319+
pass the input to another command without having to worry about the number
320+
of arguments or options defined in your own command. This can be achieved
321+
thanks to the
322+
:method:`Symfony\\Component\\Console\\Input\\ArgvInput::getRawTokens` method::
323+
324+
// ...
325+
use Symfony\Component\Process\Process;
326+
327+
protected function execute(InputInterface $input, OutputInterface $output): int
328+
{
329+
// pass the raw input of your command to the "ls" command
330+
$process = new Process(['ls', ...$input->getRawTokens(true)]);
331+
$process->setTty(true);
332+
$process->mustRun();
333+
334+
// ...
335+
}
336+
337+
You can include the current command name in the raw tokens by passing ``true``
338+
to the ``getRawTokens`` method only parameter.
339+
340+
.. versionadded:: 7.1
341+
342+
The :method:`Symfony\\Component\\Console\\Input\\ArgvInput::getRawTokens`
343+
method was introduced in Symfony 7.1.
344+
314345
Adding Argument/Option Value Completion
315346
---------------------------------------
316347

0 commit comments

Comments
 (0)