Convert ConsoleColors constants to enum cases
This commit is contained in:
parent
e1013f6c15
commit
baf11f5cb9
6 changed files with 48 additions and 48 deletions
|
@ -181,11 +181,11 @@
|
||||||
{
|
{
|
||||||
if($installed)
|
if($installed)
|
||||||
{
|
{
|
||||||
Console::out("$ext ... " . Console::formatColor("installed", ConsoleColors::LIGHT_GREEN));
|
Console::out("$ext ... " . Console::formatColor("installed", ConsoleColors::LIGHT_GREEN->value));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console::out("$ext ... " . Console::formatColor("missing", ConsoleColors::LIGHT_RED));
|
Console::out("$ext ... " . Console::formatColor("missing", ConsoleColors::LIGHT_RED->value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,11 +210,11 @@
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Console::out(Console::formatColor($full_name, ConsoleColors::GREEN) . ' Version: ' . Console::formatColor($component->getVersion(), ConsoleColors::LIGHT_MAGENTA));
|
Console::out(Console::formatColor($full_name, ConsoleColors::GREEN->value) . ' Version: ' . Console::formatColor($component->getVersion(), ConsoleColors::LIGHT_MAGENTA));
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e)
|
||||||
{
|
{
|
||||||
Console::outWarning('Cannot determine component version of ' . Console::formatColor($full_name, ConsoleColors::GREEN));
|
Console::outWarning('Cannot determine component version of ' . Console::formatColor($full_name, ConsoleColors::GREEN->value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -342,9 +342,9 @@
|
||||||
private static function printTree($data, string $prefix=''): void
|
private static function printTree($data, string $prefix=''): void
|
||||||
{
|
{
|
||||||
$symbols = [
|
$symbols = [
|
||||||
'corner' => Console::formatColor(' └─', ConsoleColors::LIGHT_RED),
|
'corner' => Console::formatColor(' └─', ConsoleColors::LIGHT_RED->value),
|
||||||
'line' => Console::formatColor(' │ ', ConsoleColors::LIGHT_RED),
|
'line' => Console::formatColor(' │ ', ConsoleColors::LIGHT_RED->value),
|
||||||
'cross' => Console::formatColor(' ├─', ConsoleColors::LIGHT_RED),
|
'cross' => Console::formatColor(' ├─', ConsoleColors::LIGHT_RED->value),
|
||||||
];
|
];
|
||||||
|
|
||||||
$keys = array_keys($data);
|
$keys = array_keys($data);
|
||||||
|
|
|
@ -117,13 +117,13 @@
|
||||||
{
|
{
|
||||||
$output = sprintf('%s (%s) [%s]',
|
$output = sprintf('%s (%s) [%s]',
|
||||||
$source->getName(),
|
$source->getName(),
|
||||||
Console::formatColor($source->getHost(), ConsoleColors::GREEN),
|
Console::formatColor($source->getHost(), ConsoleColors::GREEN->value),
|
||||||
Console::formatColor($source->getType(), ConsoleColors::YELLOW)
|
Console::formatColor($source->getType(), ConsoleColors::YELLOW->value)
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!$source->isSsl())
|
if(!$source->isSsl())
|
||||||
{
|
{
|
||||||
$output .= Console::formatColor('*', ConsoleColors::RED);
|
$output .= Console::formatColor('*', ConsoleColors::RED->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Console::out(' - ' . $output);
|
Console::out(' - ' . $output);
|
||||||
|
|
|
@ -22,39 +22,39 @@
|
||||||
|
|
||||||
namespace ncc\Enums;
|
namespace ncc\Enums;
|
||||||
|
|
||||||
final class ConsoleColors
|
enum ConsoleColors : string
|
||||||
{
|
{
|
||||||
public const DEFAULT = "\e[39m";
|
case DEFAULT = "\e[39m";
|
||||||
|
|
||||||
public const BLACK = "\e[30m";
|
case BLACK = "\e[30m";
|
||||||
|
|
||||||
public const RED = "\e[31m";
|
case RED = "\e[31m";
|
||||||
|
|
||||||
public const GREEN = "\e[32m";
|
case GREEN = "\e[32m";
|
||||||
|
|
||||||
public const YELLOW = "\e[33m";
|
case YELLOW = "\e[33m";
|
||||||
|
|
||||||
public const BLUE = "\e[34m";
|
case BLUE = "\e[34m";
|
||||||
|
|
||||||
public const MAGENTA = "\e[35m";
|
case MAGENTA = "\e[35m";
|
||||||
|
|
||||||
public const CYAN = "\e[36m";
|
case CYAN = "\e[36m";
|
||||||
|
|
||||||
public const LIGHT_GREY = "\e[37m";
|
case LIGHT_GREY = "\e[37m";
|
||||||
|
|
||||||
public const DARK_GREY = "\e[90m";
|
case DARK_GREY = "\e[90m";
|
||||||
|
|
||||||
public const LIGHT_RED = "\e[91m";
|
case LIGHT_RED = "\e[91m";
|
||||||
|
|
||||||
public const LIGHT_GREEN = "\e[92m";
|
case LIGHT_GREEN = "\e[92m";
|
||||||
|
|
||||||
public const LIGHT_YELLOW = "\e[93m";
|
case LIGHT_YELLOW = "\e[93m";
|
||||||
|
|
||||||
public const LIGHT_BLUE = "\e[94m";
|
case LIGHT_BLUE = "\e[94m";
|
||||||
|
|
||||||
public const LIGHT_MAGENTA = "\e[95m";
|
case LIGHT_MAGENTA = "\e[95m";
|
||||||
|
|
||||||
public const LIGHT_CYAN = "\e[96m";
|
case LIGHT_CYAN = "\e[96m";
|
||||||
|
|
||||||
public const WHITE = "\e[97m";
|
case WHITE = "\e[97m";
|
||||||
}
|
}
|
|
@ -174,7 +174,7 @@
|
||||||
|
|
||||||
if(!$basic)
|
if(!$basic)
|
||||||
{
|
{
|
||||||
$result = Console::formatColor($result, ConsoleColors::GREEN);
|
$result = Console::formatColor($result, ConsoleColors::GREEN->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$out[] .= $result;
|
$out[] .= $result;
|
||||||
|
@ -185,7 +185,7 @@
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$out[] .= Console::formatColor(implode(' ', $this->parameters), ConsoleColors::GREEN);
|
$out[] .= Console::formatColor(implode(' ', $this->parameters), ConsoleColors::GREEN->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,13 +53,13 @@
|
||||||
private static function setPrefix(string $log_level, string $input): string
|
private static function setPrefix(string $log_level, string $input): string
|
||||||
{
|
{
|
||||||
$input = match ($log_level) {
|
$input = match ($log_level) {
|
||||||
LogLevel::VERBOSE->value => self::formatColor('VRB:', ConsoleColors::LIGHT_CYAN) . " $input",
|
LogLevel::VERBOSE->value => self::formatColor('VRB:', ConsoleColors::LIGHT_CYAN->value) . " $input",
|
||||||
LogLevel::DEBUG->value => self::formatColor('DBG:', ConsoleColors::LIGHT_MAGENTA) . " $input",
|
LogLevel::DEBUG->value => self::formatColor('DBG:', ConsoleColors::LIGHT_MAGENTA->value) . " $input",
|
||||||
LogLevel::INFO->value => self::formatColor('INF:', ConsoleColors::WHITE) . " $input",
|
LogLevel::INFO->value => self::formatColor('INF:', ConsoleColors::WHITE->value) . " $input",
|
||||||
LogLevel::WARNING->value => self::formatColor('WRN:', ConsoleColors::YELLOW) . " $input",
|
LogLevel::WARNING->value => self::formatColor('WRN:', ConsoleColors::YELLOW->value) . " $input",
|
||||||
LogLevel::ERROR->value => self::formatColor('ERR:', ConsoleColors::LIGHT_RED) . " $input",
|
LogLevel::ERROR->value => self::formatColor('ERR:', ConsoleColors::LIGHT_RED->value) . " $input",
|
||||||
LogLevel::FATAL->value => self::formatColor('FTL:', ConsoleColors::LIGHT_RED) . " $input",
|
LogLevel::FATAL->value => self::formatColor('FTL:', ConsoleColors::LIGHT_RED->value) . " $input",
|
||||||
default => self::formatColor('MSG:', ConsoleColors::DEFAULT) . " $input",
|
default => self::formatColor('MSG:', ConsoleColors::DEFAULT->value) . " $input",
|
||||||
};
|
};
|
||||||
|
|
||||||
$tick_time = (string)microtime(true);
|
$tick_time = (string)microtime(true);
|
||||||
|
@ -82,11 +82,11 @@
|
||||||
|
|
||||||
if ($timeDiff > 1.0)
|
if ($timeDiff > 1.0)
|
||||||
{
|
{
|
||||||
$fmt_tick = self::formatColor($tick_time, ConsoleColors::LIGHT_RED);
|
$fmt_tick = self::formatColor($tick_time, ConsoleColors::LIGHT_RED->value);
|
||||||
}
|
}
|
||||||
elseif ($timeDiff > 0.5)
|
elseif ($timeDiff > 0.5)
|
||||||
{
|
{
|
||||||
$fmt_tick = self::formatColor($tick_time, ConsoleColors::LIGHT_YELLOW);
|
$fmt_tick = self::formatColor($tick_time, ConsoleColors::LIGHT_YELLOW->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,9 +155,9 @@
|
||||||
$trace_msg = null;
|
$trace_msg = null;
|
||||||
if($backtrace !== null && isset($backtrace[1]))
|
if($backtrace !== null && isset($backtrace[1]))
|
||||||
{
|
{
|
||||||
$trace_msg = self::formatColor($backtrace[1]['class'], ConsoleColors::LIGHT_GREY);
|
$trace_msg = self::formatColor($backtrace[1]['class'], ConsoleColors::LIGHT_GREY->value);
|
||||||
$trace_msg .= $backtrace[1]['type'];
|
$trace_msg .= $backtrace[1]['type'];
|
||||||
$trace_msg .= self::formatColor($backtrace[1]['function'] . '()', ConsoleColors::LIGHT_GREEN);
|
$trace_msg .= self::formatColor($backtrace[1]['function'] . '()', ConsoleColors::LIGHT_GREEN->value);
|
||||||
$trace_msg .= ' > ';
|
$trace_msg .= ' > ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@
|
||||||
|
|
||||||
if($persist)
|
if($persist)
|
||||||
{
|
{
|
||||||
return $color_code . $input . ConsoleColors::DEFAULT;
|
return $color_code . $input . ConsoleColors::DEFAULT->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $color_code . $input;
|
return $color_code . $input;
|
||||||
|
@ -236,7 +236,7 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self::out(self::formatColor('Warning: ', ConsoleColors::YELLOW) . $message, $newline);
|
self::out(self::formatColor('Warning: ', ConsoleColors::YELLOW->value) . $message, $newline);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -265,7 +265,7 @@
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
self::out(self::formatColor(ConsoleColors::RED, 'Error: ') . $message, $newline);
|
self::out(self::formatColor(ConsoleColors::RED->value, 'Error: ') . $message, $newline);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($exit_code !== null)
|
if($exit_code !== null)
|
||||||
|
@ -291,7 +291,7 @@
|
||||||
|
|
||||||
if($message !== '' && Resolver::checkLogLevel(LogLevel::ERROR->value, Main::getLogLevel()))
|
if($message !== '' && Resolver::checkLogLevel(LogLevel::ERROR->value, Main::getLogLevel()))
|
||||||
{
|
{
|
||||||
self::out(PHP_EOL . self::formatColor('Error: ', ConsoleColors::RED) . $message);
|
self::out(PHP_EOL . self::formatColor('Error: ', ConsoleColors::RED->value) . $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
self::out(PHP_EOL . '===== Exception Details =====');
|
self::out(PHP_EOL . '===== Exception Details =====');
|
||||||
|
@ -318,8 +318,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exception name without namespace
|
// Exception name without namespace
|
||||||
$trace_header = self::formatColor($e->getFile() . ':' . $e->getLine(), ConsoleColors::MAGENTA);
|
$trace_header = self::formatColor($e->getFile() . ':' . $e->getLine(), ConsoleColors::MAGENTA->value);
|
||||||
$trace_error = self::formatColor( 'Error: ', ConsoleColors::RED);
|
$trace_error = self::formatColor( 'Error: ', ConsoleColors::RED->value);
|
||||||
self::out($trace_header . ' ' . $trace_error . $e->getMessage());
|
self::out($trace_header . ' ' . $trace_error . $e->getMessage());
|
||||||
self::out(sprintf('Exception: %s', get_class($e)));
|
self::out(sprintf('Exception: %s', get_class($e)));
|
||||||
self::out(sprintf('Error code: %s', $e->getCode()));
|
self::out(sprintf('Error code: %s', $e->getCode()));
|
||||||
|
@ -329,7 +329,7 @@
|
||||||
self::out('Stack Trace:');
|
self::out('Stack Trace:');
|
||||||
foreach($trace as $item)
|
foreach($trace as $item)
|
||||||
{
|
{
|
||||||
self::out( ' - ' . self::formatColor($item['file'], ConsoleColors::RED) . ':' . $item['line']);
|
self::out( ' - ' . self::formatColor($item['file'], ConsoleColors::RED->value) . ':' . $item['line']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue