You are here

public function Runtime::getBinary in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/sebastian/environment/src/Runtime.php \SebastianBergmann\Environment\Runtime::getBinary()

Returns the path to the binary of the current runtime. Appends ' --php' to the path when the runtime is HHVM.

Return value

string

File

vendor/sebastian/environment/src/Runtime.php, line 40

Class

Runtime
Utility class for HHVM/PHP environment handling.

Namespace

SebastianBergmann\Environment

Code

public function getBinary() {

  // HHVM
  if (self::$binary === null && $this
    ->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) {
    $possibleBinaryLocations = array(
      PHP_BINDIR . '/php',
      PHP_BINDIR . '/php-cli.exe',
      PHP_BINDIR . '/php.exe',
    );
    foreach ($possibleBinaryLocations as $binary) {
      if (is_readable($binary)) {
        self::$binary = escapeshellarg($binary);
        break;
      }
    }
  }
  if (self::$binary === null) {
    self::$binary = 'php';
  }
  return self::$binary;
}