Skip to content

Commit c3bd545

Browse files
Merge branch '4.4'
* 4.4: [Form][Validator][Intl] Fix tests [Messenger] return empty envelopes when RetryableException occurs [Intl] Excludes locale from language codes (split localized language names) [FrameworkBundle] WebTestCase KernelBrowser::getContainer null return type [Intl] Fix compile type errors [Validator] Accept underscores in the URL validator as the URL will resolve correctly [Translation] Collect original locale in case of fallback translation Add types to constructors and private/final/internal methods (Batch I) [HttpFoundation] optimize normalization of headers Replace REMOTE_ADDR in trusted proxies with the current REMOTE_ADDR [ErrorHandler] Forward \Throwable Fix toolbar load when GET params are present in "_wdt" route
2 parents 53bcd7e + 597ff87 commit c3bd545

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ CHANGELOG
4040
so you likely do not use those in any app based on the SF Standard or Flex edition.
4141
* Marked all dispatched event classes as `@final`
4242
* Added `ErrorController` to enable the preview and error rendering mechanism
43+
* Getting the container from a non-booted kernel is deprecated.
4344

4445
4.3.0
4546
-----

EventListener/DebugHandlersListener.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Event\ConsoleEvent;
1717
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1818
use Symfony\Component\ErrorHandler\ErrorHandler;
19+
use Symfony\Component\ErrorHandler\Exception\FatalThrowableError;
1920
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2021
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
2122
use Symfony\Component\HttpKernel\Event\KernelEvent;
@@ -41,7 +42,7 @@ class DebugHandlersListener implements EventSubscriberInterface
4142
private $hasTerminatedWithException;
4243

4344
/**
44-
* @param callable|null $exceptionHandler A handler that will be called on Exception
45+
* @param callable|null $exceptionHandler A handler that must support \Throwable instances that will be called on Exception
4546
* @param array|int $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
4647
* @param int|null $throwAt Thrown errors in a bit field of E_* constants, or null to keep the current value
4748
* @param bool $scream Enables/disables screaming mode, where even silenced errors are logged
@@ -105,10 +106,15 @@ public function configure(object $event = null)
105106
if (method_exists($kernel = $event->getKernel(), 'terminateWithException')) {
106107
$request = $event->getRequest();
107108
$hasRun = &$this->hasTerminatedWithException;
108-
$this->exceptionHandler = static function (\Exception $e) use ($kernel, $request, &$hasRun) {
109+
$this->exceptionHandler = static function (\Throwable $e) use ($kernel, $request, &$hasRun) {
109110
if ($hasRun) {
110111
throw $e;
111112
}
113+
114+
if (!$e instanceof \Exception) {
115+
$e = new FatalThrowableError($e);
116+
}
117+
112118
$hasRun = true;
113119
$kernel->terminateWithException($e, $request);
114120
};

Kernel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ public function getProjectDir()
300300
*/
301301
public function getContainer()
302302
{
303+
if (!$this->booted) {
304+
@trigger_error('Getting the container from a non-booted kernel is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
305+
}
306+
303307
return $this->container;
304308
}
305309

KernelInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function getProjectDir();
107107
/**
108108
* Gets the current container.
109109
*
110-
* @return ContainerInterface|null A ContainerInterface instance or null when the Kernel is shutdown
110+
* @return ContainerInterface
111111
*/
112112
public function getContainer();
113113

Tests/KernelTest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ public function testConstructor()
4545
$this->assertEquals($debug, $kernel->isDebug());
4646
$this->assertFalse($kernel->isBooted());
4747
$this->assertLessThanOrEqual(microtime(true), $kernel->getStartTime());
48+
}
49+
50+
/**
51+
* @group legacy
52+
* @expectedDeprecation Getting the container from a non-booted kernel is deprecated since Symfony 4.4.
53+
*/
54+
public function testGetContainerForANonBootedKernel()
55+
{
56+
$kernel = new KernelForTest('test_env', true);
57+
58+
$this->assertFalse($kernel->isBooted());
4859
$this->assertNull($kernel->getContainer());
4960
}
5061

@@ -60,7 +71,6 @@ public function testClone()
6071
$this->assertEquals($debug, $clone->isDebug());
6172
$this->assertFalse($clone->isBooted());
6273
$this->assertLessThanOrEqual(microtime(true), $clone->getStartTime());
63-
$this->assertNull($clone->getContainer());
6474
}
6575

6676
public function testClassNameValidityGetter()
@@ -397,6 +407,18 @@ public function testTerminateReturnsSilentlyIfKernelIsNotBooted()
397407
$kernel->terminate(Request::create('/'), new Response());
398408
}
399409

410+
/**
411+
* @group legacy
412+
* @expectedDeprecation Getting the container from a non-booted kernel is deprecated since Symfony 4.4.
413+
*/
414+
public function testDeprecatedNullKernel()
415+
{
416+
$kernel = $this->getKernel();
417+
$kernel->shutdown();
418+
419+
$this->assertNull($kernel->getContainer());
420+
}
421+
400422
public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
401423
{
402424
// does not implement TerminableInterface

0 commit comments

Comments
 (0)