Extract a Process class that wraps Symfony's

This commit is contained in:
Oliver Davies 2024-02-20 08:45:00 +00:00
parent 3ed3ee85b8
commit cf89ca76a0
2 changed files with 34 additions and 21 deletions

26
src/Process/Process.php Normal file
View file

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace App\Process;
use Symfony\Component\Process\Process as SymfonyProcess;
/**
* Create a new Process instance with some extra options.
*
* @param non-empty-array<int, non-empty-string> $command
* @param string $workingDir
* @param ?string $extraArgs
*/
final class Process
{
public static function create(array $command, string $workingDir, ?string $extraArgs = null): SymfonyProcess
{
$process = new SymfonyProcess(command: array_filter([...$command, $extraArgs]));
$process->setTty(true);
$process->setWorkingDirectory($workingDir);
return $process;
}
}