From 8c8bf1204a5e10b58ed1ea10ef259729072bb7a1 Mon Sep 17 00:00:00 2001 From: Kai Eichinger Date: Thu, 13 Nov 2025 12:20:02 +0100 Subject: [PATCH 1/4] Add `HostingEnvironment::isDebug()` --- CHANGELOG.md | 6 ++++++ config/services.yaml | 1 + src/Hosting/HostingEnvironment.php | 10 ++++++++++ tests/Hosting/HostingEnvironmentTest.php | 17 +++++++++++++---- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef7f5cb..a69bcfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +vNext +===== + +* (feature) `HostingEnvironment` now exposes the `%kernel.debug%` variable as `HostingEnvironment::isDebug()`. + + 4.0.4 ===== diff --git a/config/services.yaml b/config/services.yaml index afed870..918b890 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -17,6 +17,7 @@ services: Torr\Hosting\Hosting\HostingEnvironment: $tier: !abstract defined via configuration $installationKey: !abstract defined via configuration + $isDebug: '%kernel.debug%' Torr\Hosting\BuildInfo\BuildInfoStorage: $filePath: '%kernel.project_dir%/.build-info.json' diff --git a/src/Hosting/HostingEnvironment.php b/src/Hosting/HostingEnvironment.php index a6f1a0e..f90c364 100644 --- a/src/Hosting/HostingEnvironment.php +++ b/src/Hosting/HostingEnvironment.php @@ -12,6 +12,7 @@ */ public function __construct ( HostingTier|string $tier, + private bool $isDebug, private ?string $installationKey = null, ) { @@ -54,4 +55,13 @@ public function getInstallationKey () : ?string { return $this->installationKey; } + + /** + * Returns the Symfony Debug variable (%kernel.debug%), which determines whether Symfony + * is currently being executed using the APP_DEBUG=1 environment variable. + */ + public function isDebug () : bool + { + return $this->isDebug; + } } diff --git a/tests/Hosting/HostingEnvironmentTest.php b/tests/Hosting/HostingEnvironmentTest.php index 5bd4e46..2cf692c 100644 --- a/tests/Hosting/HostingEnvironmentTest.php +++ b/tests/Hosting/HostingEnvironmentTest.php @@ -15,7 +15,7 @@ final class HostingEnvironmentTest extends TestCase */ public function testInstallationKey () : void { - $environment = new HostingEnvironment(HostingTier::PRODUCTION, "installation"); + $environment = new HostingEnvironment(HostingTier::PRODUCTION, false, "installation"); self::assertSame("installation", $environment->getInstallationKey()); } @@ -24,10 +24,10 @@ public function testInstallationKey () : void */ public function testHostingTierConstructor () : void { - $environment = new HostingEnvironment(HostingTier::PRODUCTION, "installation"); + $environment = new HostingEnvironment(HostingTier::PRODUCTION, false, "installation"); self::assertSame(HostingTier::PRODUCTION, $environment->getTier()); - $environment2 = new HostingEnvironment("staging", "installation"); + $environment2 = new HostingEnvironment("staging", false, "installation"); self::assertSame(HostingTier::STAGING, $environment2->getTier()); } @@ -49,7 +49,16 @@ public static function provideHostingTiers () : iterable */ public function testHostingTiers (string|HostingTier $value, HostingTier $expected) : void { - $environment = new HostingEnvironment($value, "installation"); + $environment = new HostingEnvironment($value, false, "installation"); self::assertSame($expected, $environment->getTier()); } + + public function testDebugFlag () : void + { + $environment = new HostingEnvironment(HostingTier::DEVELOPMENT, false, "installation"); + self::assertFalse($environment->isDebug()); + + $environment2 = new HostingEnvironment(HostingTier::PRODUCTION, true, "other-installation"); + self::assertTrue($environment2->isDebug()); + } } From 7409b8ef5e4cf051548f18da84941df0fc2d40c6 Mon Sep 17 00:00:00 2001 From: Kai Eichinger Date: Thu, 13 Nov 2025 13:38:31 +0100 Subject: [PATCH 2/4] Improve docs comment Co-authored-by: Jannik --- src/Hosting/HostingEnvironment.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Hosting/HostingEnvironment.php b/src/Hosting/HostingEnvironment.php index f90c364..94808de 100644 --- a/src/Hosting/HostingEnvironment.php +++ b/src/Hosting/HostingEnvironment.php @@ -57,8 +57,8 @@ public function getInstallationKey () : ?string } /** - * Returns the Symfony Debug variable (%kernel.debug%), which determines whether Symfony - * is currently being executed using the APP_DEBUG=1 environment variable. + * Whether the Symfony debug mode is active. This is separate from the app environment (like `prod` or `dev`) and controls whether extensive debug information is collected. + * This mode is controlled via the `APP_DEBUG` environment variable. */ public function isDebug () : bool { From 57e70ab7bee7bb489ddcdbabc9710e7e26bf7d7f Mon Sep 17 00:00:00 2001 From: Kai Eichinger Date: Thu, 13 Nov 2025 13:40:15 +0100 Subject: [PATCH 3/4] CS: Remove trailing space --- src/Hosting/HostingEnvironment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hosting/HostingEnvironment.php b/src/Hosting/HostingEnvironment.php index 94808de..90059f8 100644 --- a/src/Hosting/HostingEnvironment.php +++ b/src/Hosting/HostingEnvironment.php @@ -57,7 +57,7 @@ public function getInstallationKey () : ?string } /** - * Whether the Symfony debug mode is active. This is separate from the app environment (like `prod` or `dev`) and controls whether extensive debug information is collected. + * Whether the Symfony debug mode is active. This is separate from the app environment (like `prod` or `dev`) and controls whether extensive debug information is collected. * This mode is controlled via the `APP_DEBUG` environment variable. */ public function isDebug () : bool From be188565ba9ebedd4629c581772f0a54a872baff Mon Sep 17 00:00:00 2001 From: Kai Eichinger Date: Thu, 13 Nov 2025 13:40:26 +0100 Subject: [PATCH 4/4] Immediately release v4.1.0 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a69bcfc..d2a2c98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -vNext +4.1.0 ===== * (feature) `HostingEnvironment` now exposes the `%kernel.debug%` variable as `HostingEnvironment::isDebug()`.