diff --git a/CHANGELOG.md b/CHANGELOG.md index ef7f5cb..d2a2c98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +4.1.0 +===== + +* (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..90059f8 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; } + + /** + * 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 + { + 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()); + } }