From 9be9e873aebe226bc1e3c59b179179cf8350d51e Mon Sep 17 00:00:00 2001 From: Joel Mellon Date: Wed, 24 Nov 2021 12:34:12 -0800 Subject: [PATCH 1/4] add App::isDebug() method to detect debug mode Like App::isLocal(), isProduction(), runningInConsole(), isLocale(), etc. it makes sense to have a method on the Container to detect debug mode. I struggled with the method name, but isDebug() sort of matches most of the methods with similar functionality. I also like: * debugMode() * debugEnabled() * debugModeEnabled() * inDebugMode() --- src/Illuminate/Foundation/Application.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 6a21efb68027..f8b45756fa2b 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -607,6 +607,16 @@ public function detectEnvironment(Closure $callback) return $this['env'] = (new EnvironmentDetector)->detect($callback, $args); } + /** + * Determine if the application is running with debug mode enabled. + * + * @return bool + */ + public function isDebug() + { + return (bool) $this['config']->get('app.debug'); + } + /** * Determine if the application is running in the console. * From f245a6c76a5ccffb76340ceba5e93e42855b94d6 Mon Sep 17 00:00:00 2001 From: Joel Mellon Date: Wed, 24 Nov 2021 13:08:29 -0800 Subject: [PATCH 2/4] add isDebug() unit test --- tests/Foundation/FoundationApplicationTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Foundation/FoundationApplicationTest.php b/tests/Foundation/FoundationApplicationTest.php index 1f8849f3d419..989162f32941 100755 --- a/tests/Foundation/FoundationApplicationTest.php +++ b/tests/Foundation/FoundationApplicationTest.php @@ -2,6 +2,7 @@ namespace Illuminate\Tests\Foundation; +use Illuminate\Config\Repository; use Illuminate\Contracts\Support\DeferrableProvider; use Illuminate\Foundation\Application; use Illuminate\Foundation\Bootstrap\RegisterFacades; @@ -239,6 +240,19 @@ public function testEnvironmentHelpers() $this->assertFalse($testing->isProduction()); } + public function testDebugHelper() + { + $debugOff = new Application; + $debugOff['config'] = new Repository(['app' => ['debug' => false]]); + + $this->assertFalse($debugOff->isDebug()); + + $debugOn = new Application; + $debugOn['config'] = new Repository(['app' => ['debug' => true]]); + + $this->assertTrue($debugOn->isDebug()); + } + public function testMethodAfterLoadingEnvironmentAddsClosure() { $app = new Application; From 1fe107612b95a7661a941dcf0acb4cfb10914818 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 24 Nov 2021 20:06:16 -0600 Subject: [PATCH 3/4] Update Application.php --- src/Illuminate/Foundation/Application.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index f8b45756fa2b..04d49afccf26 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -607,16 +607,6 @@ public function detectEnvironment(Closure $callback) return $this['env'] = (new EnvironmentDetector)->detect($callback, $args); } - /** - * Determine if the application is running with debug mode enabled. - * - * @return bool - */ - public function isDebug() - { - return (bool) $this['config']->get('app.debug'); - } - /** * Determine if the application is running in the console. * @@ -641,6 +631,16 @@ public function runningUnitTests() return $this->bound('env') && $this['env'] === 'testing'; } + /** + * Determine if the application is running with debug mode enabled. + * + * @return bool + */ + public function hasDebugModeEnabled() + { + return (bool) $this['config']->get('app.debug'); + } + /** * Register all of the configured providers. * From e330c59149742cd81a0ea27f33c5bc8b868dd4c4 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 24 Nov 2021 20:06:41 -0600 Subject: [PATCH 4/4] Update FoundationApplicationTest.php --- tests/Foundation/FoundationApplicationTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Foundation/FoundationApplicationTest.php b/tests/Foundation/FoundationApplicationTest.php index 989162f32941..63abffc4e3ef 100755 --- a/tests/Foundation/FoundationApplicationTest.php +++ b/tests/Foundation/FoundationApplicationTest.php @@ -245,12 +245,12 @@ public function testDebugHelper() $debugOff = new Application; $debugOff['config'] = new Repository(['app' => ['debug' => false]]); - $this->assertFalse($debugOff->isDebug()); + $this->assertFalse($debugOff->hasDebugModeEnabled()); $debugOn = new Application; $debugOn['config'] = new Repository(['app' => ['debug' => true]]); - $this->assertTrue($debugOn->isDebug()); + $this->assertTrue($debugOn->hasDebugModeEnabled()); } public function testMethodAfterLoadingEnvironmentAddsClosure()