Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit97e2f07

Browse files
[HttpKernel] Fix handling non-catchable fatal errors
This reverts PR#27519 this commit18c2dde,reversing changes made toac1189a.
1 parent9fbfc4c commit97e2f07

File tree

7 files changed

+38
-63
lines changed

7 files changed

+38
-63
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,6 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
721721
$container->setParameter('debug.error_handler.throw_at',0);
722722
}
723723

724-
$definition->replaceArgument(4,$debug);
725-
$definition->replaceArgument(6,$debug);
726-
727724
if ($debug &&class_exists(DebugProcessor::class)) {
728725
$definition =newDefinition(DebugProcessor::class);
729726
$definition->setPublic(false);

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.xml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
<argumenttype="service"id="logger"on-invalid="null" />
1919
<argument>null</argument><!-- Log levels map for enabled error levels-->
2020
<argument>%debug.error_handler.throw_at%</argument>
21-
<argument>true</argument>
21+
<argument>%kernel.debug%</argument>
2222
<argumenttype="service"id="debug.file_link_formatter"></argument>
23-
<argument>true</argument>
23+
<argument>%kernel.debug%</argument>
24+
<argument>%kernel.charset%</argument>
2425
</service>
2526

2627
<serviceid="debug.file_link_formatter"class="Symfony\Component\HttpKernel\Debug\FileLinkFormatter">

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,6 @@
6767
<argumenttype="service"id="router"on-invalid="ignore" />
6868
</service>
6969

70-
<serviceid="http_exception_listener"class="Symfony\Component\HttpKernel\EventListener\ExceptionListener">
71-
<tagname="kernel.event_listener"event="kernel.exception"method="onKernelException"priority="-2048" />
72-
<tagname="kernel.reset"method="reset" />
73-
<argument>null</argument>
74-
<argument>null</argument>
75-
<argument>%kernel.debug%</argument>
76-
<argument>%kernel.charset%</argument>
77-
<argument>%debug.file_link_format%</argument>
78-
</service>
79-
8070
<serviceid="validate_request_listener"class="Symfony\Component\HttpKernel\EventListener\ValidateRequestListener">
8171
<tagname="kernel.event_subscriber" />
8272
</service>

‎src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
useSymfony\Component\Console\Event\ConsoleEvent;
1717
useSymfony\Component\Console\Output\ConsoleOutputInterface;
1818
useSymfony\Component\Debug\ErrorHandler;
19+
useSymfony\Component\Debug\Exception\FlattenException;
1920
useSymfony\Component\Debug\ExceptionHandler;
2021
useSymfony\Component\EventDispatcher\Event;
2122
useSymfony\Component\EventDispatcher\EventSubscriberInterface;
23+
useSymfony\Component\HttpFoundation\Request;
24+
useSymfony\Component\HttpFoundation\Response;
2225
useSymfony\Component\HttpKernel\Debug\FileLinkFormatter;
2326
useSymfony\Component\HttpKernel\Event\KernelEvent;
27+
useSymfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
2428
useSymfony\Component\HttpKernel\KernelEvents;
2529

2630
/**
@@ -37,6 +41,7 @@ class DebugHandlersListener implements EventSubscriberInterface
3741
private$scream;
3842
private$fileLinkFormat;
3943
private$scope;
44+
private$charset;
4045
private$firstCall =true;
4146
private$hasTerminatedWithException;
4247

@@ -49,7 +54,7 @@ class DebugHandlersListener implements EventSubscriberInterface
4954
* @param string|FileLinkFormatter|null $fileLinkFormat The format for links to source files
5055
* @param bool $scope Enables/disables scoping mode
5156
*/
52-
publicfunction__construct(callable$exceptionHandler =null,LoggerInterface$logger =null,$levels =E_ALL, ?int$throwAt =E_ALL,bool$scream =true,$fileLinkFormat =null,bool$scope =true)
57+
publicfunction__construct(callable$exceptionHandler =null,LoggerInterface$logger =null,$levels =E_ALL, ?int$throwAt =E_ALL,bool$scream =true,$fileLinkFormat =null,bool$scope =true,string$charset =null)
5358
{
5459
$this->exceptionHandler =$exceptionHandler;
5560
$this->logger =$logger;
@@ -58,6 +63,7 @@ public function __construct(callable $exceptionHandler = null, LoggerInterface $
5863
$this->scream =$scream;
5964
$this->fileLinkFormat =$fileLinkFormat;
6065
$this->scope =$scope;
66+
$this->charset =$charset;
6167
}
6268

6369
/**
@@ -144,6 +150,26 @@ public function configure(Event $event = null)
144150
}
145151
}
146152

153+
/**
154+
* @internal
155+
*/
156+
publicfunctiononKernelException(GetResponseForExceptionEvent$event)
157+
{
158+
if (!$this->hasTerminatedWithException || !$event->isMasterRequest()) {
159+
return;
160+
}
161+
162+
$debug =$this->scream &&$this->scope;
163+
$controller =function (Request$request)use ($debug) {
164+
$e =$request->attributes->get('exception');
165+
$handler =newExceptionHandler($debug,$this->charset,$this->fileLinkFormat);
166+
167+
returnnewResponse($handler->getHtml($e),$e->getStatusCode(),$e->getHeaders());
168+
};
169+
170+
(newExceptionListener($controller,$this->logger,$debug))->onKernelException($event);
171+
}
172+
147173
publicstaticfunctiongetSubscribedEvents()
148174
{
149175
$events = [KernelEvents::REQUEST => ['configure',2048]];
@@ -152,6 +178,8 @@ public static function getSubscribedEvents()
152178
$events[ConsoleEvents::COMMAND] = ['configure',2048];
153179
}
154180

181+
$events[KernelEvents::EXCEPTION] = ['onKernelException', -2048];
182+
155183
return$events;
156184
}
157185
}

‎src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php‎

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313

1414
usePsr\Log\LoggerInterface;
1515
useSymfony\Component\Debug\Exception\FlattenException;
16-
useSymfony\Component\Debug\ExceptionHandler;
1716
useSymfony\Component\EventDispatcher\EventDispatcherInterface;
1817
useSymfony\Component\EventDispatcher\EventSubscriberInterface;
1918
useSymfony\Component\HttpFoundation\Request;
20-
useSymfony\Component\HttpFoundation\Response;
2119
useSymfony\Component\HttpKernel\Event\FilterResponseEvent;
2220
useSymfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
2321
useSymfony\Component\HttpKernel\Exception\HttpExceptionInterface;
@@ -35,17 +33,12 @@ class ExceptionListener implements EventSubscriberInterface
3533
protected$controller;
3634
protected$logger;
3735
protected$debug;
38-
private$charset;
39-
private$fileLinkFormat;
40-
private$isTerminating =false;
4136

42-
publicfunction__construct($controller,LoggerInterface$logger =null,$debug =false,string$charset =null,$fileLinkFormat =null)
37+
publicfunction__construct($controller,LoggerInterface$logger =null,$debug =false)
4338
{
4439
$this->controller =$controller;
4540
$this->logger =$logger;
4641
$this->debug =$debug;
47-
$this->charset =$charset;
48-
$this->fileLinkFormat =$fileLinkFormat;
4942
}
5043

5144
publicfunctionlogKernelException(GetResponseForExceptionEvent$event)
@@ -58,16 +51,9 @@ public function logKernelException(GetResponseForExceptionEvent $event)
5851
publicfunctiononKernelException(GetResponseForExceptionEvent$event)
5952
{
6053
if (null ===$this->controller) {
61-
if (!$event->isMasterRequest()) {
62-
return;
63-
}
64-
if (!$this->isTerminating) {
65-
$this->isTerminating =true;
66-
67-
return;
68-
}
69-
$this->isTerminating =false;
54+
return;
7055
}
56+
7157
$exception =$event->getException();
7258
$request =$this->duplicateRequest($exception,$event->getRequest());
7359
$eventDispatcher =\func_num_args() >2 ?func_get_arg(2) :null;
@@ -104,11 +90,6 @@ public function onKernelException(GetResponseForExceptionEvent $event)
10490
}
10591
}
10692

107-
publicfunctionreset()
108-
{
109-
$this->isTerminating =false;
110-
}
111-
11293
publicstaticfunctiongetSubscribedEvents()
11394
{
11495
return [
@@ -147,12 +128,8 @@ protected function logException(\Exception $exception, $message)
147128
protectedfunctionduplicateRequest(\Exception$exception,Request$request)
148129
{
149130
$attributes = [
150-
'exception' =>$exception = FlattenException::create($exception),
151-
'_controller' =>$this->controller ?:function ()use ($exception) {
152-
$handler =newExceptionHandler($this->debug,$this->charset,$this->fileLinkFormat);
153-
154-
returnnewResponse($handler->getHtml($exception),$exception->getStatusCode(),$exception->getHeaders());
155-
},
131+
'_controller' =>$this->controller,
132+
'exception' => FlattenException::create($exception),
156133
'logger' =>$this->loggerinstanceof DebugLoggerInterface ?$this->logger :null,
157134
];
158135
$request =$request->duplicate(null,null,$attributes);

‎src/Symfony/Component/HttpKernel/Tests/EventListener/DebugHandlersListenerTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public function testConsoleEvent()
104104
$xListeners = [
105105
KernelEvents::REQUEST => [[$listener,'configure']],
106106
ConsoleEvents::COMMAND => [[$listener,'configure']],
107+
KernelEvents::EXCEPTION => [[$listener,'onKernelException']],
107108
];
108109
$this->assertSame($xListeners,$dispatcher->getListeners());
109110

‎src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,6 @@ public function testCSPHeaderIsRemoved()
155155
$this->assertFalse($response->headers->has('content-security-policy'),'CSP header has been removed');
156156
$this->assertFalse($dispatcher->hasListeners(KernelEvents::RESPONSE),'CSP removal listener has been removed');
157157
}
158-
159-
publicfunctiontestNullController()
160-
{
161-
$listener =newExceptionListener(null);
162-
$kernel =$this->getMockBuilder(HttpKernelInterface::class)->getMock();
163-
$kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request$request) {
164-
$controller =$request->attributes->get('_controller');
165-
166-
return$controller();
167-
});
168-
$request = Request::create('/');
169-
$event =newGetResponseForExceptionEvent($kernel,$request, HttpKernelInterface::MASTER_REQUEST,new \Exception('foo'));
170-
171-
$listener->onKernelException($event);
172-
$this->assertNull($event->getResponse());
173-
174-
$listener->onKernelException($event);
175-
$this->assertContains('Whoops, looks like something went wrong.',$event->getResponse()->getContent());
176-
}
177158
}
178159

179160
class TestLoggerextends Loggerimplements DebugLoggerInterface

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp