public static function color(string
$text, string
$foreground, ?string
$background = null, ?string
$format = null
): string
{ if (!
static::
$isColored ||
$text === ''
) { return $text;
} if (!
array_key_exists($foreground,
static::
$foreground_colors)) { throw CLIException::
forInvalidColor('foreground',
$foreground);
} if ($background !== null && !
array_key_exists($background,
static::
$background_colors)) { throw CLIException::
forInvalidColor('background',
$background);
} $newText = '';
// Detect if color method was already in use with this text
if (strpos($text, "\033[0m"
) !== false
) { $pattern = '/\\033\\[0;.+?\\033\\[0m/u';