Determine the proper PHP executable.

https://github.com/laravel/framework/pull/22448

@return string
505120
public static function phpBinary()
    {
        if (Eye::laravelVersionIs('<', '5.5.26')) {
            return SymfonyProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false));
        }

        return LaravelProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false));
    }
1159158
public function compile()
    {
        $compiled = $this->command;

        // If callable, return the function itself
        if (is_callable($compiled)) {
            return $compiled;
        }

        // Augment with any supplied arguments
        foreach ($this->args as $key => $value) {
            $compiled .= ' ' . escapeshellarg($key);
            if ($value !== null) {
                $compiled .= ' ' . escapeshellarg($value);
            }
        }

        // Add the boilerplate to redirect the output to file/s
        if (count($this->outputTo) > 0) {
            $compiled .= ' | tee ';
            $compiled .= $this->outputMode === 'a' ? '-a ' : '';
            foreach ($this->outputTo as $file) {
                $compiled .= $file . ' ';
            }

            $compiled = trim($compiled);
        }

        // Add boilerplate to remove lockfile after execution
        if ($this->lockFile) {
            $compiled .= '; rm ' . $this->lockFile;
        }

        // Add boilerplate to run in background
        if ($this->canRunInBackground()) {
            // Parentheses are need execute the chain of commands in a subshell
            // that can then run in background
            $compiled = '(' . $compiled . ') > /dev/null 2>&1 &';
        }

        return trim($compiled);
    }
199480
public function checkPhpVersion() {
		$phpVesion = $this->_modelConfigInstaller->getPhpVersionConfig();
		if (empty($phpVesion)) {
			return null;
		}

		$result = true;
		foreach ($phpVesion as $phpVesionItem) {
			if (!is_array($phpVesionItem)) {
				continue;
			}

			$phpVesionItem += ['', null];
			list($version, $operator) = $phpVesionItem;
			if (empty($operator)) {
				$operator = '==';
			}

			$checkResult = false;
			if (!empty($version)) {
				$checkResult = version_compare(PHP_VERSION, $version, $operator);
			}
			if (!$checkResult) {
				$result = false;
			}
		}

		return $result;
	}
234506
public function execute()
    {
        if (!$this->tryAndProcessRules()) {
            return false;
        }

        $phpmdBinaryPath = $this->phpci->findBinary('phpmd');

        $this->executePhpMd($phpmdBinaryPath);

        $errorCount = $this->processReport(trim($this->phpci->getLastOutput()));
        $this->build->storeMeta('phpmd-warnings', $errorCount);

        return $this->wasLastExecSuccessful($errorCount);
    }
15685
public function buildCode() {
        $library = $this->getLibrary();
        $alias = $this->getAlias();
        if (empty($alias)) {
            $alias = $library;
        }
        return '#Include "' . $library . '" as ' . $alias . PHP_EOL;
    }
22957
private function routable() : bool
  {
    $routesFolder = config('app.dir') . 'routes' . DIRECTORY_SEPARATOR;

    if (!file_exists($routesFolder . 'api.php' )) {
      $this->exception('Could not find api routes.');
      return false;
    }

    if (!file_exists($routesFolder . 'web.php' )) {
      $this->exception('Could not find web routes.');
      return false;
    }

    return true;
  }
770566
public function GetCode () {
		if ($this->code === NULL) {
			$phpCode = http_response_code();
			$this->code = $phpCode === FALSE ? static::OK : $phpCode;
		}
		return $this->code;
	}
759882
protected function serverCommand()
    {
        return sprintf('%s -S %s:%s %s',
            ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false)),
            $this->host(),
            $this->port(),
            ProcessUtils::escapeArgument(base_path('server.php'))
        );
    }
1162606
public static function verify()
    {
        // PHP interpreter version
        self::checkSystemVersion();

        // BCMath
        self::isFunctionExists('bcmul', self::getErrorMessage('bcmath'));
        self::isFunctionExists('bcdiv', self::getErrorMessage('bcmath'));

        // Filter
        self::isFunctionExists('filter_var', self::getErrorMessage('filter'));

        // Hash
        self::isFunctionExists('hash', self::getErrorMessage('hash'));

        // XMLReader
        self::isClassExists('XMLReader', self::getErrorMessage('xmlreader'));

        // XMLWriter
        if (\Genesis\Config::getInterface('builder') == 'xml') {
            self::isClassExists('XMLWriter', self::getErrorMessage('xmlwriter'));
        }

        // cURL
        if (\Genesis\Config::getInterface('network') == 'curl') {
            self::isFunctionExists('curl_init', self::getErrorMessage('curl'));
        }
    }
852499
private function getExecutedCommand()
    {
        $pathDirs = explode(PATH_SEPARATOR, $_SERVER['PATH']);
        $executedCommand = $_SERVER['PHP_SELF'];
        $executedCommandDir = dirname($executedCommand);

        if (in_array($executedCommandDir, $pathDirs)) {
            $executedCommand = basename($executedCommand);
        }

        return $executedCommand;
    }
622300
protected static function find_php_cli_path() {
        global $CFG;

        if (!empty($CFG->pathtophp) && is_executable(trim($CFG->pathtophp))) {
            return $CFG->pathtophp;
        }

        return false;
    }
668338
public static function getBinary(): string
    {
        // Custom PHP path
        if (self::$binary === null) {
            if ((self::$binary = getenv('PHP_BINARY_CUSTOM')) === false) {
                self::$binary = PHP_BINARY;
            }
        }

        // HHVM
        if (self::$binary === null && self::isHHVM()) {
            if ((self::$binary = getenv('PHP_BINARY')) === false) {
                self::$binary = PHP_BINARY;
            }
            self::$binary = escapeshellarg(self::$binary) . ' --php';
        }

        // PHP >= 5.4.0
        if (self::$binary === null && defined('PHP_BINARY')) {
            self::$binary = escapeshellarg(PHP_BINARY);
        }

        // PHP < 5.4.0
        if (self::$binary === null) {
            if (PHP_SAPI === 'cli' && isset($_SERVER['_'])) {
                if (strpos($_SERVER['_'], 'phpunit') !== false) {
                    $file = file($_SERVER['_']);

                    if (strpos($file[0], ' ') !== false) {
                        $tmp = explode(' ', $file[0]);
                        self::$binary = escapeshellarg(trim($tmp[1]));
                    } else {
                        self::$binary = escapeshellarg(ltrim(trim($file[0]), '#!'));
                    }
                } elseif (strpos(basename($_SERVER['_']), 'php') !== false) {
                    self::$binary = escapeshellarg($_SERVER['_']);
                }
            }
        }

        if (self::$binary === null) {
            $binaryLocations = [
                PHP_BINDIR . '/php',
                PHP_BINDIR . '/php-cli.exe',
                PHP_BINDIR . '/php.exe',
            ];

            foreach ($binaryLocations as $binary) {
                if (is_readable($binary)) {
                    self::$binary = escapeshellarg($binary);
                    break;
                }
            }
        }

        if (self::$binary === null) {
            self::$binary = 'php';
        }

        return self::$binary;
    }
645165
public function getExitCode()
    {
        if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
            throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
        }

        $this->updateStatus(false);

        return $this->exitcode;
    }
196312
public static function getComposerExecutor()
    {
        $executor = PHP_BINARY . ' ';
        $composer = static::getComposerLocation();

        if ($composer !== static::DEFAULT_PATH && is_executable($composer)) {
            $file = fopen($composer, 'rb');
            $firstLine = fgets($file);
            fclose($file);

            if (!preg_match('/^#!.+php/i', $firstLine)) {
                $executor = '';
            }
        }

        return $executor . $composer;
    }
887535
public function fixCode() {
    $command = "'{$this->bin}/phpcbf'";
    $task = $this->taskExecStack()
      ->dir($this->bltRoot)
      ->exec($command);
    $result = $task->run();

    return $result->getExitCode();
  }
717241
private function determineExtension()
    {
        $ext = 'php';
        if (in_array($this->driverClass, $this->extensionToDriver)) {
            $map = array_flip($this->extensionToDriver);
            $ext = $map[$this->driverClass];
        }
        return $ext;
    }
1192158
private function getComposer(): string
	{
		$composer = $this->tempDir . $this->composer;

		$temp = $this->tempDir . $this->composerDir;
		if (!file_exists($temp)) {
			mkdir($temp);
		}

		$home = 'COMPOSER_HOME="' . $temp . '" ';

		if (!file_exists($composer)) {
			$expectedSignature = trim(file_get_contents('https://composer.github.io/installer.sig'));
			copy('https://getcomposer.org/installer', $this->tempDir . '/composer-setup.php');
			$actualSignature = hash_file('SHA384', $this->tempDir . '/composer-setup.php');
			if ($expectedSignature === $actualSignature) {
				$command = 'cd ' . $this->tempDir . ';'
					. $home . 'php composer-setup.php;';
				exec($command, $output);
				foreach ($output as $str) {
					if (!empty($str)) {
						Debugger::log($str, 'composer');
					}
				}
				unlink($this->tempDir . '/composer-setup.php');
			} else {
				Debugger::log('Invalid installer signature', 'composer');
			}
		}
		return $home . $composer;
	}