diff --git a/src/CLI/Console.php b/src/CLI/Console.php index 2c2da1a..122e991 100644 --- a/src/CLI/Console.php +++ b/src/CLI/Console.php @@ -4,6 +4,26 @@ class Console { + const MODE_DEVELOPMENT = 'development'; + const MODE_PRODUCTION = 'production'; + + /** + * @var string + */ + protected static string $mode = Console::MODE_DEVELOPMENT; + + /** + * Set a mode for console logs + * + * @param string $mode + * + * @return void + */ + public static function setMode(string $mode): void + { + self::$mode = $mode; + } + /** * Title * @@ -27,6 +47,10 @@ public static function title(string $title): bool */ public static function log(string $message): int|false { + if(self::$mode === Console::MODE_PRODUCTION) { + return 0; + } + return \fwrite(STDOUT, $message . "\n"); } diff --git a/tests/CLI/ConsoleTest.php b/tests/CLI/ConsoleTest.php index f55f644..697e81a 100755 --- a/tests/CLI/ConsoleTest.php +++ b/tests/CLI/ConsoleTest.php @@ -24,6 +24,11 @@ public function testLogs() $this->assertEquals(19, Console::warning('warning')); $this->assertEquals(15, Console::error('error')); $this->assertEquals('this is an answer', Console::confirm('this is a question')); + + Console::setMode(Console::MODE_PRODUCTION); + $this->assertEquals(0, Console::log('log')); + Console::setMode(Console::MODE_DEVELOPMENT); + $this->assertEquals(4, Console::log('log')); } public function testExecuteBasic()