SoliDry /
api-generator
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SoliDry\Helpers; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * Class Console - provides primitive console operations |
||
| 7 | * |
||
| 8 | * @package SoliDry\Helpers |
||
| 9 | */ |
||
| 10 | class Console |
||
| 11 | { |
||
| 12 | // actions |
||
| 13 | public const CREATED = 'created'; |
||
| 14 | |||
| 15 | // user colors |
||
| 16 | public const COLOR_RED = 'red'; |
||
| 17 | public const COLOR_GREEN = 'green'; |
||
| 18 | public const COLOR_YELLOW = 'yellow'; |
||
| 19 | |||
| 20 | public const ANSI_COLOR_RED = "\x1b[31m"; |
||
| 21 | public const ANSI_COLOR_GREEN = "\x1b[32m"; |
||
| 22 | public const ANSI_COLOR_YELLOW = "\x1b[33m"; |
||
| 23 | public const ANSI_COLOR_RESET = "\x1b[0m"; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var array|string[] |
||
| 27 | */ |
||
| 28 | private static array $colorMaps = [ |
||
| 29 | self::COLOR_RED => self::ANSI_COLOR_RED, |
||
| 30 | self::COLOR_GREEN => self::ANSI_COLOR_GREEN, |
||
| 31 | self::COLOR_YELLOW => self::ANSI_COLOR_YELLOW, |
||
| 32 | ]; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Console output helper/beautifier |
||
| 36 | * |
||
| 37 | * @param string $str |
||
| 38 | * @param null $color |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 39 | */ |
||
| 40 | public static function out(string $str, $color = null) : void |
||
| 41 | { |
||
| 42 | echo (($color === null) ? '' : self::$colorMaps[$color]) . $str . (($color === null) ? '' : self::ANSI_COLOR_RESET) . PHP_EOL; |
||
|
0 ignored issues
–
show
|
|||
| 43 | } |
||
| 44 | } |