Skip to content

Commit

Permalink
#11 - Implement new Color method: fatal()
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Mar 22, 2020
1 parent 14128c9 commit 88e6644
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
8 changes: 4 additions & 4 deletions phalcon-migrations
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ try {
$command = new Migration($parser);
$command->run();
} catch (CommandsException $commandsException) {
echo Color::error($commandsException->getMessage());
echo Color::error($commandsException->getMessage(), 'Exception Error: ');
exit(1);
} catch (RuntimeException $runtimeException) {
echo Color::error($runtimeException->getMessage());
echo Color::error($runtimeException->getMessage(), 'Runtime Error: ');
exit(1);
} catch (DbException $dbException) {
echo Color::error($dbException->getMessage());
echo Color::error($dbException->getMessage(), 'DB Error: ');
exit(1);
}
} catch (Throwable $e) {
fwrite(STDERR, 'FATAL ERROR: ' . $e->getMessage() . PHP_EOL);
echo Color::fatal($e->getMessage());
exit(1);
}
24 changes: 22 additions & 2 deletions src/Console/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,12 @@ public static function head(string $msg): string
*
* @static
* @param string $msg
* @param string $prefix
* @return string
*/
public static function error(string $msg): string
public static function error(string $msg, string $prefix = 'Error: '): string
{
$msg = 'Error: ' . $msg;
$msg = $prefix . $msg;
$space = self::tabSpaces($msg);
$out = static::colorize(str_pad(' ', $space), Color::FG_WHITE, Color::AT_BOLD, Color::BG_RED) . PHP_EOL;
$out .= static::colorize(' ' . $msg . ' ', Color::FG_WHITE, Color::AT_BOLD, Color::BG_RED) . PHP_EOL;
Expand All @@ -187,6 +188,25 @@ public static function error(string $msg): string
return $out;
}

/**
* Color style for fatal error messages.
*
* @static
* @param string $msg
* @param string $prefix
* @return string
*/
public static function fatal(string $msg, string $prefix = 'Fatal Error: '): string
{
$msg = $prefix . $msg;
$space = self::tabSpaces($msg);
$out = static::colorize(str_pad(' ', $space), Color::FG_LIGHT_GRAY, Color::AT_BOLD, Color::BG_RED) . PHP_EOL;
$out .= static::colorize(' ' . $msg . ' ', Color::FG_LIGHT_GRAY, Color::AT_BOLD, Color::BG_RED) . PHP_EOL;
$out .= static::colorize(str_pad(' ', $space), Color::FG_LIGHT_GRAY, Color::AT_BOLD, Color::BG_RED) . PHP_EOL;

return $out;
}

/**
* Color style for success messages.
*
Expand Down

0 comments on commit 88e6644

Please sign in to comment.