diff --git a/src/System/Integrate/Application.php b/src/System/Integrate/Application.php index d11a44f8..f00b4fb7 100644 --- a/src/System/Integrate/Application.php +++ b/src/System/Integrate/Application.php @@ -251,7 +251,8 @@ public function loadConfig(ConfigRepository $configs): void $this->set('config', fn (): ConfigRepository => $configs); // base env - $this->set('environment', $configs['ENVIRONMENT']); + $this->set('environment', $configs['APP_ENV'] ?? $configs['ENVIRONMENT']); + $this->set('app.debug', $configs['APP_DEBUG']); // application path $this->setAppPath($this->basePath()); $this->setModelPath($configs['MODEL_PATH']); @@ -293,6 +294,7 @@ public function defaultConfigs() 'time_zone' => 'Asia/Jakarta', 'APP_KEY' => '', 'ENVIRONMENT' => 'dev', + 'APP_DEBUG' => false, 'COMMAND_PATH' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Commands' . DIRECTORY_SEPARATOR, 'CONTROLLER_PATH' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR, @@ -818,6 +820,16 @@ public function environment() return $this->get('environment'); } + /** + * Detect application debug enable. + * + * @return bool + */ + public function isDebugMode() + { + return $this->get('app.debug'); + } + /** * Detect application prodaction mode. * diff --git a/tests/Integrate/ApplicationTest.php b/tests/Integrate/ApplicationTest.php index e128929d..6110da5d 100644 --- a/tests/Integrate/ApplicationTest.php +++ b/tests/Integrate/ApplicationTest.php @@ -52,6 +52,46 @@ public function itCanLoadConfigFromDefault() $app->flush(); } + /** + * @test + */ + public function itCanLoadEnvironment() + { + $app = new Application('/'); + + $env = $app->defaultConfigs(); + $app->loadConfig(new ConfigRepository($env)); + $this->assertTrue($app->isDev()); + $this->assertFalse($app->isProduction()); + + $env['ENVIRONMENT'] = 'test'; + + $app->loadConfig(new ConfigRepository($env)); + $this->assertEquals('test', $app->environment()); + + // APP_ENV + $env['APP_ENV'] = 'dev'; + + $app->loadConfig(new ConfigRepository($env)); + $this->assertEquals('dev', $app->environment()); + + $app->flush(); + } + + /** + * @test + */ + public function itCanDetectDebugMode() + { + $app = new Application('/'); + + $env = $app->defaultConfigs(); + $app->loadConfig(new ConfigRepository($env)); + $this->assertFalse($app->isDebugMode()); + + $app->flush(); + } + /** @test */ public function itCanNotDuplicateRegister() { @@ -247,6 +287,7 @@ private function defaultConfigs() 'time_zone' => 'Asia/Jakarta', 'APP_KEY' => '', 'ENVIRONMENT' => 'dev', + 'APP_DEBUG' => false, 'COMMAND_PATH' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Commands' . DIRECTORY_SEPARATOR, 'CONTROLLER_PATH' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR,