3 * This file is part of the Environment package.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace SebastianBergmann\Environment;
14 * Utility class for HHVM/PHP environment handling.
21 private static $binary;
24 * Returns true when Xdebug is supported or
25 * the runtime used is PHPDBG (PHP >= 7.0).
29 public function canCollectCodeCoverage()
31 return $this->hasXdebug() || $this->hasPHPDBGCodeCoverage();
35 * Returns the path to the binary of the current runtime.
36 * Appends ' --php' to the path when the runtime is HHVM.
40 public function getBinary()
43 if (self::$binary === null && $this->isHHVM()) {
44 if ((self::$binary = getenv('PHP_BINARY')) === false) {
45 self::$binary = PHP_BINARY;
48 self::$binary = escapeshellarg(self::$binary) . ' --php';
52 if (self::$binary === null && defined('PHP_BINARY')) {
53 if (PHP_BINARY !== '') {
54 self::$binary = escapeshellarg(PHP_BINARY);
59 if (self::$binary === null) {
60 if (PHP_SAPI == 'cli' && isset($_SERVER['_'])) {
61 if (strpos($_SERVER['_'], 'phpunit') !== false) {
62 $file = file($_SERVER['_']);
64 if (strpos($file[0], ' ') !== false) {
65 $tmp = explode(' ', $file[0]);
66 self::$binary = escapeshellarg(trim($tmp[1]));
68 self::$binary = escapeshellarg(ltrim(trim($file[0]), '#!'));
70 } elseif (strpos(basename($_SERVER['_']), 'php') !== false) {
71 self::$binary = escapeshellarg($_SERVER['_']);
76 if (self::$binary === null) {
77 $possibleBinaryLocations = array(
79 PHP_BINDIR . '/php-cli.exe',
80 PHP_BINDIR . '/php.exe'
83 foreach ($possibleBinaryLocations as $binary) {
84 if (is_readable($binary)) {
85 self::$binary = escapeshellarg($binary);
91 if (self::$binary === null) {
92 self::$binary = 'php';
101 public function getNameWithVersion()
103 return $this->getName() . ' ' . $this->getVersion();
109 public function getName()
111 if ($this->isHHVM()) {
113 } elseif ($this->isPHPDBG()) {
123 public function getVendorUrl()
125 if ($this->isHHVM()) {
126 return 'http://hhvm.com/';
128 return 'https://secure.php.net/';
135 public function getVersion()
137 if ($this->isHHVM()) {
145 * Returns true when the runtime used is PHP and Xdebug is loaded.
149 public function hasXdebug()
151 return ($this->isPHP() || $this->isHHVM()) && extension_loaded('xdebug');
155 * Returns true when the runtime used is HHVM.
159 public function isHHVM()
161 return defined('HHVM_VERSION');
165 * Returns true when the runtime used is PHP without the PHPDBG SAPI.
169 public function isPHP()
171 return !$this->isHHVM() && !$this->isPHPDBG();
175 * Returns true when the runtime used is PHP with the PHPDBG SAPI.
179 public function isPHPDBG()
181 return PHP_SAPI === 'phpdbg' && !$this->isHHVM();
185 * Returns true when the runtime used is PHP with the PHPDBG SAPI
186 * and the phpdbg_*_oplog() functions are available (PHP >= 7.0).
190 public function hasPHPDBGCodeCoverage()
192 return $this->isPHPDBG() && function_exists('phpdbg_start_oplog');