-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from asgrim/adjust-timeouts-for-process-invoka…
…tions Adjust timeouts for invoked processes
- Loading branch information
Showing
4 changed files
with
84 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Php\Pie\Util; | ||
|
||
use Symfony\Component\Process\Exception\ProcessFailedException; | ||
use Symfony\Component\Process\Process as SymfonyProcess; | ||
|
||
use function trim; | ||
|
||
final class Process | ||
{ | ||
/** @psalm-suppress UnusedConstructor */ | ||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* Just a helper to invoke a Symfony Process command with a simplified API | ||
* for the common invocations we have in PIE. | ||
* | ||
* Things to note: | ||
* - uses mustRun (i.e. throws exception if command execution fails) | ||
* - very short timeout by default (5 seconds) | ||
* - output is trimmed | ||
* | ||
* @param list<string> $command | ||
* | ||
* @throws ProcessFailedException | ||
*/ | ||
public static function run(array $command, string|null $workingDirectory = null, int|null $timeout = 5): string | ||
{ | ||
return trim((new SymfonyProcess($command, $workingDirectory, timeout: $timeout)) | ||
->mustRun() | ||
->getOutput()); | ||
} | ||
} |