2019-12-03 15:41:56 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Utilities;
|
|
|
|
|
2020-03-19 17:18:19 +03:00
|
|
|
use Symfony\Component\Process\PhpExecutableFinder;
|
2019-12-03 15:41:56 +03:00
|
|
|
use Symfony\Component\Process\Process;
|
|
|
|
|
|
|
|
class Console
|
|
|
|
{
|
2020-03-19 17:18:19 +03:00
|
|
|
public static function run($string, $all_output = false, $timeout = 0)
|
2019-12-03 15:41:56 +03:00
|
|
|
{
|
2020-03-19 17:18:19 +03:00
|
|
|
$command = static::formatCommandString($string);
|
|
|
|
|
2020-03-16 19:35:58 +03:00
|
|
|
$process = Process::fromShellCommandline($command, base_path());
|
2020-02-05 10:24:18 +03:00
|
|
|
$process->setTimeout($timeout);
|
2019-12-03 15:41:56 +03:00
|
|
|
|
|
|
|
$process->run();
|
|
|
|
|
|
|
|
if ($process->isSuccessful()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-19 17:34:24 +03:00
|
|
|
$output = $all_output ? $process->getOutput() : $process->getErrorOutput();
|
|
|
|
|
|
|
|
logger($output);
|
|
|
|
|
|
|
|
return $output;
|
2019-12-03 15:41:56 +03:00
|
|
|
}
|
2020-03-19 17:18:19 +03:00
|
|
|
|
|
|
|
public static function getPhpBinary()
|
|
|
|
{
|
2020-05-09 16:12:57 +03:00
|
|
|
$bin = (new PhpExecutableFinder)->find(false);
|
|
|
|
|
|
|
|
return !empty($bin) ? $bin : 'php';
|
2020-03-19 17:18:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getArtisanBinary()
|
|
|
|
{
|
|
|
|
return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function formatCommandString($string)
|
|
|
|
{
|
|
|
|
return sprintf('%s %s %s', static::getPhpBinary(), static::getArtisanBinary(), $string);
|
|
|
|
}
|
2019-12-03 15:41:56 +03:00
|
|
|
}
|