Closed
Description
Description
Extract \Symfony\Component\Process\Process::escapeArgument
to a separate service class, so that external classes can make use of the shell argument escaping.
Commands like \Symfony\Component\Process\Process::fromShellCommandline
accept raw input, but sometimes the client wants to make sure the arguments passed to that method are actually escaped. Or is argument binding the only preferred way to achieve this?
Example
<?php
use Symfony\Component\Process\ArgumentEscaper;
use Symfony\Component\Process\Process;
function test_piped_command(string $param): void
{
$escaper = new ArgumentEscaper();
$command = [];
$command[] = 'echo ' . $escaper->escapeArgument($param);
$command[] = 'md5sum';
$shellCommand = implode('|', $command);
$process = Process::fromShellCommandline($command);
$process->run();
}