Example #1
0
    /**
     * @param string $phpExecutable
     * @return PhpExecutable
     * @throws \Exception
     */
    public static function getPhpExecutable($phpExecutable)
    {
        $codeToExecute = <<<PHP
echo "PHP;", PHP_VERSION_ID, ";", defined('HPHP_VERSION') ? HPHP_VERSION : null;
PHP;
        $process = new Process(escapeshellarg($phpExecutable) . ' -n -r ' . escapeshellarg($codeToExecute));
        $process->waitForFinish();
        try {
            if ($process->getStatusCode() !== 0 && $process->getStatusCode() !== 255) {
                throw new RunTimeException("Unable to execute '{$phpExecutable}'.");
            }
            return self::getPhpExecutableFromOutput($phpExecutable, $process->getOutput());
        } catch (RunTimeException $e) {
            // Try HHVM type
            $process = new Process(escapeshellarg($phpExecutable) . ' --php -r ' . escapeshellarg($codeToExecute));
            $process->waitForFinish();
            if ($process->getStatusCode() !== 0 && $process->getStatusCode() !== 255) {
                throw new RunTimeException("Unable to execute '{$phpExecutable}'.");
            }
            return self::getPhpExecutableFromOutput($phpExecutable, $process->getOutput(), $isHhvmType = true);
        }
    }
 /**
  * @param string $gitExecutable
  * @return bool
  */
 public static function gitExists($gitExecutable)
 {
     $process = new Process(escapeshellcmd($gitExecutable) . ' --version');
     $process->waitForFinish();
     return $process->getStatusCode() === 0;
 }