initial
This commit is contained in:
+132
@@ -0,0 +1,132 @@
|
||||
# Changes in sebastianbergmann/environment
|
||||
|
||||
All notable changes in `sebastianbergmann/environment` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
|
||||
|
||||
## [4.2.5] - 2024-03-01
|
||||
|
||||
* No code changes, only updated `.gitattributes` to not export non-essential files.
|
||||
|
||||
## [4.2.4] - 2020-11-30
|
||||
|
||||
### Changed
|
||||
|
||||
* Changed PHP version constraint in `composer.json` from `^7.1` to `>=7.1`
|
||||
|
||||
## [4.2.3] - 2019-11-20
|
||||
|
||||
### Changed
|
||||
|
||||
* Implemented [#50](https://github.com/sebastianbergmann/environment/pull/50): Windows improvements to console capabilities
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed [#49](https://github.com/sebastianbergmann/environment/issues/49): Detection how OpCache handles docblocks does not work correctly when PHPDBG is used
|
||||
|
||||
## [4.2.2] - 2019-05-05
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed [#44](https://github.com/sebastianbergmann/environment/pull/44): `TypeError` in `Console::getNumberOfColumnsInteractive()`
|
||||
|
||||
## [4.2.1] - 2019-04-25
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed an issue in `Runtime::getCurrentSettings()`
|
||||
|
||||
## [4.2.0] - 2019-04-25
|
||||
|
||||
### Added
|
||||
|
||||
* Implemented [#36](https://github.com/sebastianbergmann/environment/pull/36): `Runtime::getCurrentSettings()`
|
||||
|
||||
## [4.1.0] - 2019-02-01
|
||||
|
||||
### Added
|
||||
|
||||
* Implemented `Runtime::getNameWithVersionAndCodeCoverageDriver()` method
|
||||
* Implemented [#34](https://github.com/sebastianbergmann/environment/pull/34): Support for PCOV extension
|
||||
|
||||
## [4.0.2] - 2019-01-28
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed [#33](https://github.com/sebastianbergmann/environment/issues/33): `Runtime::discardsComments()` returns true too eagerly
|
||||
|
||||
### Removed
|
||||
|
||||
* Removed support for Zend Optimizer+ in `Runtime::discardsComments()`
|
||||
|
||||
## [4.0.1] - 2018-11-25
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed [#31](https://github.com/sebastianbergmann/environment/issues/31): Regressions in `Console` class
|
||||
|
||||
## [4.0.0] - 2018-10-23 [YANKED]
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed [#25](https://github.com/sebastianbergmann/environment/pull/25): `Console::hasColorSupport()` does not work on Windows
|
||||
|
||||
### Removed
|
||||
|
||||
* This component is no longer supported on PHP 7.0
|
||||
|
||||
## [3.1.0] - 2017-07-01
|
||||
|
||||
### Added
|
||||
|
||||
* Implemented [#21](https://github.com/sebastianbergmann/environment/issues/21): Equivalent of `PHP_OS_FAMILY` (for PHP < 7.2)
|
||||
|
||||
## [3.0.4] - 2017-06-20
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed [#20](https://github.com/sebastianbergmann/environment/pull/20): PHP 7 mode of HHVM not forced
|
||||
|
||||
## [3.0.3] - 2017-05-18
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed [#18](https://github.com/sebastianbergmann/environment/issues/18): `Uncaught TypeError: preg_match() expects parameter 2 to be string, null given`
|
||||
|
||||
## [3.0.2] - 2017-04-21
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed [#17](https://github.com/sebastianbergmann/environment/issues/17): `Uncaught TypeError: trim() expects parameter 1 to be string, boolean given`
|
||||
|
||||
## [3.0.1] - 2017-04-21
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed inverted logic in `Runtime::discardsComments()`
|
||||
|
||||
## [3.0.0] - 2017-04-21
|
||||
|
||||
### Added
|
||||
|
||||
* Implemented `Runtime::discardsComments()` for querying whether the PHP runtime discards annotations
|
||||
|
||||
### Removed
|
||||
|
||||
* This component is no longer supported on PHP 5.6
|
||||
|
||||
[4.2.5]: https://github.com/sebastianbergmann/phpunit/compare/4.2.4...4.2.5
|
||||
[4.2.4]: https://github.com/sebastianbergmann/phpunit/compare/4.2.3...4.2.4
|
||||
[4.2.3]: https://github.com/sebastianbergmann/phpunit/compare/4.2.2...4.2.3
|
||||
[4.2.2]: https://github.com/sebastianbergmann/phpunit/compare/4.2.1...4.2.2
|
||||
[4.2.1]: https://github.com/sebastianbergmann/phpunit/compare/4.2.0...4.2.1
|
||||
[4.2.0]: https://github.com/sebastianbergmann/phpunit/compare/4.1.0...4.2.0
|
||||
[4.1.0]: https://github.com/sebastianbergmann/phpunit/compare/4.0.2...4.1.0
|
||||
[4.0.2]: https://github.com/sebastianbergmann/phpunit/compare/4.0.1...4.0.2
|
||||
[4.0.1]: https://github.com/sebastianbergmann/phpunit/compare/66691f8e2dc4641909166b275a9a4f45c0e89092...4.0.1
|
||||
[4.0.0]: https://github.com/sebastianbergmann/phpunit/compare/3.1.0...66691f8e2dc4641909166b275a9a4f45c0e89092
|
||||
[3.1.0]: https://github.com/sebastianbergmann/phpunit/compare/3.0...3.1.0
|
||||
[3.0.4]: https://github.com/sebastianbergmann/phpunit/compare/3.0.3...3.0.4
|
||||
[3.0.3]: https://github.com/sebastianbergmann/phpunit/compare/3.0.2...3.0.3
|
||||
[3.0.2]: https://github.com/sebastianbergmann/phpunit/compare/3.0.1...3.0.2
|
||||
[3.0.1]: https://github.com/sebastianbergmann/phpunit/compare/3.0.0...3.0.1
|
||||
[3.0.0]: https://github.com/sebastianbergmann/phpunit/compare/2.0...3.0.0
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
sebastian/environment
|
||||
|
||||
Copyright (c) 2014-2019, Sebastian Bergmann <sebastian@phpunit.de>.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
* Neither the name of Sebastian Bergmann nor the names of his
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
# sebastian/environment
|
||||
|
||||
This component provides functionality that helps writing PHP code that has runtime-specific (PHP / HHVM) execution paths.
|
||||
|
||||
[](https://packagist.org/packages/sebastian/environment)
|
||||
[](https://php.net/)
|
||||
[](https://travis-ci.org/sebastianbergmann/environment)
|
||||
|
||||
## Installation
|
||||
|
||||
You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
|
||||
|
||||
composer require sebastian/environment
|
||||
|
||||
If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
|
||||
|
||||
composer require --dev sebastian/environment
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "sebastian/environment",
|
||||
"description": "Provides functionality to handle HHVM/PHP environments",
|
||||
"keywords": ["environment","hhvm","xdebug"],
|
||||
"homepage": "http://www.github.com/sebastianbergmann/environment",
|
||||
"license": "BSD-3-Clause",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Sebastian Bergmann",
|
||||
"email": "sebastian@phpunit.de"
|
||||
}
|
||||
],
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"sort-packages": true
|
||||
},
|
||||
"prefer-stable": true,
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.5"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-posix": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"src/"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.2-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/environment.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Environment;
|
||||
|
||||
final class Console
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public const STDIN = 0;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public const STDOUT = 1;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public const STDERR = 2;
|
||||
|
||||
/**
|
||||
* Returns true if STDOUT supports colorization.
|
||||
*
|
||||
* This code has been copied and adapted from
|
||||
* Symfony\Component\Console\Output\StreamOutput.
|
||||
*/
|
||||
public function hasColorSupport(): bool
|
||||
{
|
||||
if ('Hyper' === \getenv('TERM_PROGRAM')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->isWindows()) {
|
||||
// @codeCoverageIgnoreStart
|
||||
return (\defined('STDOUT') && \function_exists('sapi_windows_vt100_support') && @\sapi_windows_vt100_support(\STDOUT))
|
||||
|| false !== \getenv('ANSICON')
|
||||
|| 'ON' === \getenv('ConEmuANSI')
|
||||
|| 'xterm' === \getenv('TERM');
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
if (!\defined('STDOUT')) {
|
||||
// @codeCoverageIgnoreStart
|
||||
return false;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return $this->isInteractive(\STDOUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of columns of the terminal.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getNumberOfColumns(): int
|
||||
{
|
||||
if (!$this->isInteractive(\defined('STDIN') ? \STDIN : self::STDIN)) {
|
||||
return 80;
|
||||
}
|
||||
|
||||
if ($this->isWindows()) {
|
||||
return $this->getNumberOfColumnsWindows();
|
||||
}
|
||||
|
||||
return $this->getNumberOfColumnsInteractive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the file descriptor is an interactive terminal or not.
|
||||
*
|
||||
* Normally, we want to use a resource as a parameter, yet sadly it's not always awailable,
|
||||
* eg when running code in interactive console (`php -a`), STDIN/STDOUT/STDERR constants are not defined.
|
||||
*
|
||||
* @param int|resource $fileDescriptor
|
||||
*/
|
||||
public function isInteractive($fileDescriptor = self::STDOUT): bool
|
||||
{
|
||||
if (\is_resource($fileDescriptor)) {
|
||||
// These functions require a descriptor that is a real resource, not a numeric ID of it
|
||||
if (\function_exists('stream_isatty') && @\stream_isatty($fileDescriptor)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$stat = @\fstat(\STDOUT);
|
||||
// Check if formatted mode is S_IFCHR
|
||||
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
|
||||
}
|
||||
|
||||
return \function_exists('posix_isatty') && @\posix_isatty($fileDescriptor);
|
||||
}
|
||||
|
||||
private function isWindows(): bool
|
||||
{
|
||||
return \DIRECTORY_SEPARATOR === '\\';
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function getNumberOfColumnsInteractive(): int
|
||||
{
|
||||
if (\function_exists('shell_exec') && \preg_match('#\d+ (\d+)#', \shell_exec('stty size') ?: '', $match) === 1) {
|
||||
if ((int) $match[1] > 0) {
|
||||
return (int) $match[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (\function_exists('shell_exec') && \preg_match('#columns = (\d+);#', \shell_exec('stty') ?: '', $match) === 1) {
|
||||
if ((int) $match[1] > 0) {
|
||||
return (int) $match[1];
|
||||
}
|
||||
}
|
||||
|
||||
return 80;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function getNumberOfColumnsWindows(): int
|
||||
{
|
||||
$ansicon = \getenv('ANSICON');
|
||||
$columns = 80;
|
||||
|
||||
if (\is_string($ansicon) && \preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', \trim($ansicon), $matches)) {
|
||||
$columns = $matches[1];
|
||||
} elseif (\function_exists('proc_open')) {
|
||||
$process = \proc_open(
|
||||
'mode CON',
|
||||
[
|
||||
1 => ['pipe', 'w'],
|
||||
2 => ['pipe', 'w'],
|
||||
],
|
||||
$pipes,
|
||||
null,
|
||||
null,
|
||||
['suppress_errors' => true]
|
||||
);
|
||||
|
||||
if (\is_resource($process)) {
|
||||
$info = \stream_get_contents($pipes[1]);
|
||||
|
||||
\fclose($pipes[1]);
|
||||
\fclose($pipes[2]);
|
||||
\proc_close($process);
|
||||
|
||||
if (\preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) {
|
||||
$columns = $matches[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $columns - 1;
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/environment.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Environment;
|
||||
|
||||
final class OperatingSystem
|
||||
{
|
||||
/**
|
||||
* Returns PHP_OS_FAMILY (if defined (which it is on PHP >= 7.2)).
|
||||
* Returns a string (compatible with PHP_OS_FAMILY) derived from PHP_OS otherwise.
|
||||
*/
|
||||
public function getFamily(): string
|
||||
{
|
||||
if (\defined('PHP_OS_FAMILY')) {
|
||||
return \PHP_OS_FAMILY;
|
||||
}
|
||||
|
||||
if (\DIRECTORY_SEPARATOR === '\\') {
|
||||
return 'Windows';
|
||||
}
|
||||
|
||||
switch (\PHP_OS) {
|
||||
case 'Darwin':
|
||||
return 'Darwin';
|
||||
|
||||
case 'DragonFly':
|
||||
case 'FreeBSD':
|
||||
case 'NetBSD':
|
||||
case 'OpenBSD':
|
||||
return 'BSD';
|
||||
|
||||
case 'Linux':
|
||||
return 'Linux';
|
||||
|
||||
case 'SunOS':
|
||||
return 'Solaris';
|
||||
|
||||
default:
|
||||
return 'Unknown';
|
||||
}
|
||||
}
|
||||
}
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/environment.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Environment;
|
||||
|
||||
/**
|
||||
* Utility class for HHVM/PHP environment handling.
|
||||
*/
|
||||
final class Runtime
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $binary;
|
||||
|
||||
/**
|
||||
* Returns true when Xdebug or PCOV is available or
|
||||
* the runtime used is PHPDBG.
|
||||
*/
|
||||
public function canCollectCodeCoverage(): bool
|
||||
{
|
||||
return $this->hasXdebug() || $this->hasPCOV() || $this->hasPHPDBGCodeCoverage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when Zend OPcache is loaded, enabled, and is configured to discard comments.
|
||||
*/
|
||||
public function discardsComments(): bool
|
||||
{
|
||||
if (!\extension_loaded('Zend OPcache')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (\ini_get('opcache.save_comments') !== '0') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((\PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg') && \ini_get('opcache.enable_cli') === '1') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (\PHP_SAPI !== 'cli' && \PHP_SAPI !== 'phpdbg' && \ini_get('opcache.enable') === '1') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the binary of the current runtime.
|
||||
* Appends ' --php' to the path when the runtime is HHVM.
|
||||
*/
|
||||
public function getBinary(): string
|
||||
{
|
||||
// HHVM
|
||||
if (self::$binary === null && $this->isHHVM()) {
|
||||
// @codeCoverageIgnoreStart
|
||||
if ((self::$binary = \getenv('PHP_BINARY')) === false) {
|
||||
self::$binary = \PHP_BINARY;
|
||||
}
|
||||
|
||||
self::$binary = \escapeshellarg(self::$binary) . ' --php' .
|
||||
' -d hhvm.php7.all=1';
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
if (self::$binary === null && \PHP_BINARY !== '') {
|
||||
self::$binary = \escapeshellarg(\PHP_BINARY);
|
||||
}
|
||||
|
||||
if (self::$binary === null) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$possibleBinaryLocations = [
|
||||
\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;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
if (self::$binary === null) {
|
||||
// @codeCoverageIgnoreStart
|
||||
self::$binary = 'php';
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return self::$binary;
|
||||
}
|
||||
|
||||
public function getNameWithVersion(): string
|
||||
{
|
||||
return $this->getName() . ' ' . $this->getVersion();
|
||||
}
|
||||
|
||||
public function getNameWithVersionAndCodeCoverageDriver(): string
|
||||
{
|
||||
if (!$this->canCollectCodeCoverage() || $this->hasPHPDBGCodeCoverage()) {
|
||||
return $this->getNameWithVersion();
|
||||
}
|
||||
|
||||
if ($this->hasXdebug()) {
|
||||
return \sprintf(
|
||||
'%s with Xdebug %s',
|
||||
$this->getNameWithVersion(),
|
||||
\phpversion('xdebug')
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->hasPCOV()) {
|
||||
return \sprintf(
|
||||
'%s with PCOV %s',
|
||||
$this->getNameWithVersion(),
|
||||
\phpversion('pcov')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
if ($this->isHHVM()) {
|
||||
// @codeCoverageIgnoreStart
|
||||
return 'HHVM';
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
if ($this->isPHPDBG()) {
|
||||
// @codeCoverageIgnoreStart
|
||||
return 'PHPDBG';
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return 'PHP';
|
||||
}
|
||||
|
||||
public function getVendorUrl(): string
|
||||
{
|
||||
if ($this->isHHVM()) {
|
||||
// @codeCoverageIgnoreStart
|
||||
return 'https://hhvm.com/';
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return 'https://www.php.net/';
|
||||
}
|
||||
|
||||
public function getVersion(): string
|
||||
{
|
||||
if ($this->isHHVM()) {
|
||||
// @codeCoverageIgnoreStart
|
||||
return HHVM_VERSION;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return \PHP_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the runtime used is PHP and Xdebug is loaded.
|
||||
*/
|
||||
public function hasXdebug(): bool
|
||||
{
|
||||
return ($this->isPHP() || $this->isHHVM()) && \extension_loaded('xdebug');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the runtime used is HHVM.
|
||||
*/
|
||||
public function isHHVM(): bool
|
||||
{
|
||||
return \defined('HHVM_VERSION');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the runtime used is PHP without the PHPDBG SAPI.
|
||||
*/
|
||||
public function isPHP(): bool
|
||||
{
|
||||
return !$this->isHHVM() && !$this->isPHPDBG();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the runtime used is PHP with the PHPDBG SAPI.
|
||||
*/
|
||||
public function isPHPDBG(): bool
|
||||
{
|
||||
return \PHP_SAPI === 'phpdbg' && !$this->isHHVM();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the runtime used is PHP with the PHPDBG SAPI
|
||||
* and the phpdbg_*_oplog() functions are available (PHP >= 7.0).
|
||||
*/
|
||||
public function hasPHPDBGCodeCoverage(): bool
|
||||
{
|
||||
return $this->isPHPDBG();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the runtime used is PHP with PCOV loaded and enabled
|
||||
*/
|
||||
public function hasPCOV(): bool
|
||||
{
|
||||
return $this->isPHP() && \extension_loaded('pcov') && \ini_get('pcov.enabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the loaded php.ini file (if any) as well as all
|
||||
* additional php.ini files from the additional ini dir for
|
||||
* a list of all configuration settings loaded from files
|
||||
* at startup. Then checks for each php.ini setting passed
|
||||
* via the `$values` parameter whether this setting has
|
||||
* been changed at runtime. Returns an array of strings
|
||||
* where each string has the format `key=value` denoting
|
||||
* the name of a changed php.ini setting with its new value.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCurrentSettings(array $values): array
|
||||
{
|
||||
$diff = [];
|
||||
$files = [];
|
||||
|
||||
if ($file = \php_ini_loaded_file()) {
|
||||
$files[] = $file;
|
||||
}
|
||||
|
||||
if ($scanned = \php_ini_scanned_files()) {
|
||||
$files = \array_merge(
|
||||
$files,
|
||||
\array_map(
|
||||
'trim',
|
||||
\explode(",\n", $scanned)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($files as $ini) {
|
||||
$config = \parse_ini_file($ini, true);
|
||||
|
||||
foreach ($values as $value) {
|
||||
$set = \ini_get($value);
|
||||
|
||||
if (isset($config[$value]) && $set != $config[$value]) {
|
||||
$diff[] = \sprintf('%s=%s', $value, $set);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $diff;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user