Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
4.1.0
=====

* (feature) `HostingEnvironment` now exposes the `%kernel.debug%` variable as `HostingEnvironment::isDebug()`.


4.0.4
=====

Expand Down
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 10 additions & 0 deletions src/Hosting/HostingEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
public function __construct (
HostingTier|string $tier,
private bool $isDebug,
private ?string $installationKey = null,
)
{
Expand Down Expand Up @@ -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;
}
}
17 changes: 13 additions & 4 deletions tests/Hosting/HostingEnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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());
}

Expand All @@ -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());
}
}