Use enums for status codes
This commit is contained in:
@ -11,20 +11,6 @@ declare(strict_types = 1);
|
||||
*/
|
||||
final class MDConsole {
|
||||
|
||||
const STATUS_NOTICE = 0;
|
||||
const STATUS_UPDATE = 1;
|
||||
const STATUS_DELETION = 2;
|
||||
const STATUS_ERROR = 3;
|
||||
const STATUS_SKIPPED = 4;
|
||||
|
||||
const CONSOLE_LEVEL_COLORS = [
|
||||
self::STATUS_NOTICE => "",
|
||||
self::STATUS_ERROR => "41", // 0: Red background | Problem
|
||||
self::STATUS_UPDATE => "42", // 1: Green background | Edited automatically
|
||||
self::STATUS_DELETION => "44", // 2: Blue background | Deleted
|
||||
self::STATUS_SKIPPED => "40", // 2: Blue background | Deleted
|
||||
];
|
||||
|
||||
const CONSOLE_LOG_USED_RESOURCES_ENABLED = 1;
|
||||
const CONSOLE_LOG_USED_RESOURCES_DISABLED = 0;
|
||||
|
||||
@ -81,17 +67,17 @@ final class MDConsole {
|
||||
/**
|
||||
* Formats a message uniformly, maybe also to stdout.
|
||||
*
|
||||
* @param string $context Context this is called from.
|
||||
* @param integer $level Level of the notification.
|
||||
* @param integer $editedNo Number of edited entries.
|
||||
* @param string $additionalNote Optional, additional note.
|
||||
* @param string $link Link.
|
||||
* @param string $context Context this is called from.
|
||||
* @param MDConsoleStatus $level Level of the notification.
|
||||
* @param integer $editedNo Number of edited entries.
|
||||
* @param string $additionalNote Optional, additional note.
|
||||
* @param string $link Link.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final public static function write(string $context, int $level = self::STATUS_NOTICE, int $editedNo = 0, string $additionalNote = "", string $link = ""):void {
|
||||
final public static function write(string $context, MDConsoleStatus $level = MDConsoleStatus::NOTICE, int $editedNo = 0, string $additionalNote = "", string $link = ""):void {
|
||||
|
||||
if (self::$verbose === false and $level === self::STATUS_NOTICE) return;
|
||||
if (self::$verbose === false and $level === MDConsoleStatus::NOTICE) return;
|
||||
|
||||
// Get parts for generating the message to log.
|
||||
$additionalNote = \strtr($additionalNote, ["ä" => "ae", "ö" => "oe", "ü" => "ue"]);
|
||||
@ -100,7 +86,7 @@ final class MDConsole {
|
||||
// Generate the message to log.
|
||||
# $message = sprintf("%1$07s", memory_get_usage()) . " :: {$date} :: {$msg}" . PHP_EOL;
|
||||
|
||||
$levelColor = self::CONSOLE_LEVEL_COLORS[$level];
|
||||
$levelColor = $level->color();
|
||||
|
||||
if ($link === "") {
|
||||
echo \sprintf("\033[1;30;" . $levelColor . "m_____\033[0m\033[0m %-20s \033[40m::\033[0m # \033[32m%+9s\033[0m \033[40m::\033[0m 📝 %-50s \033[40m::\033[0m 📅 %+20s\n", $context, $editedNo, $additionalNote, $date);
|
||||
|
Reference in New Issue
Block a user