Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e9dbec

Browse files
committed
bug #41402 [HttpKernel] Throw when HttpKernel is created and the env is empty (nicolas-grekas)
This PR was merged into the 5.3 branch. Discussion ---------- [HttpKernel] Throw when HttpKernel is created and the env is empty | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Providing an empty env leads to an undefined behavior, better forbid it. This will fail at compile time, so it should be safe; but still submitting on 5.3 for extra safety. Commits ------- 1a87f26 [HttpKernel] Throw when HttpKernel is created and the env is empty
2 parents 24a1c28 + 1a87f26 commit 7e9dbec

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
8787

8888
public function __construct(string $environment, bool $debug)
8989
{
90-
$this->environment = $environment;
90+
if (!$this->environment = $environment) {
91+
throw new \InvalidArgumentException(sprintf('Invalid environment provided to "%s": the environment cannot be empty.', get_debug_type($this)));
92+
}
93+
9194
$this->debug = $debug;
9295
}
9396

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ public function testConstructor()
5555
$this->assertLessThanOrEqual(microtime(true), $kernel->getStartTime());
5656
}
5757

58+
public function testEmptyEnv()
59+
{
60+
$this->expectException(\InvalidArgumentException::class);
61+
$this->expectExceptionMessage(sprintf('Invalid environment provided to "%s": the environment cannot be empty.', KernelForTest::class));
62+
63+
new KernelForTest('', false);
64+
}
65+
5866
public function testClone()
5967
{
6068
$env = 'test_env';

0 commit comments

Comments
 (0)