for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Spiral Framework.
*
* @license MIT
* @author Anton Titov (Wolfy-J)
*/
declare(strict_types=1);
namespace Spiral\Debug;
* Describes the env PHP script is running within.
final class System
{
* Return true if PHP running in CLI mode.
* @codeCoverageIgnore
* @return bool
public static function isCLI(): bool
if (!empty(getenv('RR'))) {
// Do not treat RoadRunner as CLI.
return false;
}
if (php_sapi_name() === 'cli') {
return true;
* Returns true if the STDOUT supports colorization.
* @link https://github.com/symfony/Console/blob/master/Output/StreamOutput.php#L94
* @param mixed $stream
public static function isColorsSupported($stream = STDOUT): bool
if ('Hyper' === getenv('TERM_PROGRAM')) {
try {
if (\DIRECTORY_SEPARATOR === '\\') {
return (
function_exists('sapi_windows_vt100_support')
&& @sapi_windows_vt100_support($stream)
) || getenv('ANSICON') !== false
|| getenv('ConEmuANSI') == 'ON'
|| getenv('TERM') == 'xterm';
if (\function_exists('stream_isatty')) {
return @stream_isatty($stream);
if (\function_exists('posix_isatty')) {
return @posix_isatty($stream);
$stat = @fstat($stream);
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
} catch (\Throwable $e) {