2019-03-23 17:47:46 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Internal\ExecutionEnvironment;
|
|
|
|
|
2019-06-26 22:52:29 +02:00
|
|
|
use function exec;
|
|
|
|
use function sprintf;
|
|
|
|
|
2019-03-23 17:47:46 +01:00
|
|
|
/**
|
|
|
|
* @author Kitamura Satoshi <with.no.parachute@gmail.com>
|
|
|
|
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
|
|
|
|
*
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
final class SystemCommandExecutor
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Execute command.
|
|
|
|
*
|
|
|
|
* @param string $command
|
|
|
|
*
|
|
|
|
* @throws \RuntimeException
|
|
|
|
*
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public function execute(string $command) : array
|
|
|
|
{
|
|
|
|
exec($command, $result, $returnValue);
|
|
|
|
|
|
|
|
if ($returnValue === 0) {
|
|
|
|
/** @var string[] */
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new \RuntimeException(sprintf('Failed to execute command: %s', $command), $returnValue);
|
|
|
|
}
|
|
|
|
}
|