Skip to content

Commit

Permalink
Add support for Symfony 5 to process runner
Browse files Browse the repository at this point in the history
Brought up in #98.
  • Loading branch information
franzliedke committed Dec 18, 2020
1 parent 9fcf9a1 commit e866e64
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Shell/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Studio\Shell;

use ReflectionClass;
use RuntimeException;
use Symfony\Component\Process\Process;

class Shell
{
public static function run($task, $directory = null)
{
$process = new Process("$task", $directory);
$process = static::makeProcess($task, $directory);
$process->setTimeout(3600);

$process->run();
Expand All @@ -22,4 +23,17 @@ public static function run($task, $directory = null)

return $process->getOutput();
}

private function makeProcess($task, $directory)
{
$reflection = new ReflectionClass(Process::class);
$params = $reflection->getConstructor()->getParameters();
$type = $params[0]->getType();

if ($type && $type->getName() === 'array') { // Symfony 5
return new Process(explode(' ', $task), $directory);
} else { // Older versions
return new Process($task, $directory);
}
}
}

0 comments on commit e866e64

Please sign in to comment.