Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
87e5aede
Commit
87e5aede
authored
13 years ago
by
Larry Garfield
Browse files
Options
Downloads
Patches
Plain Diff
Convert all exception handling to be part of the event dispatcher, for consistency.
parent
f9fe640f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/lib/Drupal/Core/DrupalKernel.php
+41
-10
41 additions, 10 deletions
core/lib/Drupal/Core/DrupalKernel.php
with
41 additions
and
10 deletions
core/lib/Drupal/Core/DrupalKernel.php
+
41
−
10
View file @
87e5aede
...
...
@@ -12,6 +12,9 @@
use
Symfony\Component\HttpKernel\KernelEvents
;
use
Symfony\Component\EventDispatcher\EventDispatcher
;
use
Symfony\Component\EventDispatcher\Event
;
use
Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
;
use
Exception
;
/**
* @file
...
...
@@ -26,6 +29,31 @@ class DrupalKernel implements HttpKernelInterface {
function
handle
(
Request
$request
,
$type
=
self
::
MASTER_REQUEST
,
$catch
=
true
)
{
try
{
$dispatcher
=
new
EventDispatcher
();
//$dispatcher->addSubscriber(new \Symfony\Component\HttpKernel\EventListener\ExceptionListener());
// Quick and dirty attempt at wrapping our rendering logic as is.
$dispatcher
->
addListener
(
KernelEvents
::
VIEW
,
function
(
Event
$event
)
{
$page_callback_result
=
$event
->
getControllerResult
();
$event
->
setResponse
(
new
Response
(
drupal_render_page
(
$page_callback_result
)));
});
$dispatcher
->
addListener
(
KernelEvents
::
EXCEPTION
,
function
(
Event
$event
)
use
(
$request
)
{
debug
(
$request
->
getAcceptableContentTypes
());
if
(
in_array
(
'text/html'
,
$request
->
getAcceptableContentTypes
()))
{
if
(
$event
->
getException
()
instanceof
ResourceNotFoundException
)
{
$event
->
setResponse
(
new
Response
(
'Not Found'
,
404
));
}
}
});
// Resolve a routing context(path, etc) using the routes object to a
// Set a routing context to translate.
$context
=
new
RequestContext
();
...
...
@@ -39,18 +67,21 @@ function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) {
$controller
=
$resolver
->
getController
(
$request
);
$arguments
=
$resolver
->
getArguments
(
$request
,
$controller
);
$dispatcher
=
new
EventDispatcher
();
// Quick and dirty attempt at wrapping our rendering logic as is.
$dispatcher
->
addListener
(
KernelEvents
::
VIEW
,
function
(
Event
$event
)
{
$page_callback_result
=
$event
->
getControllerResult
();
$event
->
setResponse
(
new
Response
(
drupal_render_page
(
$page_callback_result
)));
});
$kernel
=
new
HttpKernel
(
$dispatcher
,
$resolver
);
re
turn
$kernel
->
handle
(
$request
);
$
re
sponse
=
$kernel
->
handle
(
$request
);
}
catch
(
ResourceNotFoundException
$e
)
{
$response
=
new
Response
(
'Not Found'
,
404
);
catch
(
Exception
$e
)
{
$error_event
=
new
GetResponseForExceptionEvent
(
$this
,
$request
,
$this
->
type
,
$e
);
$dispatcher
->
dispatch
(
KernelEvents
::
EXCEPTION
,
$error_event
);
if
(
$error_event
->
hasResponse
())
{
$response
=
$error_event
->
getResponse
();
}
else
{
$response
=
new
Response
(
'An error occurred'
,
500
);
}
//$response = new Response('Not Found', 404);
}
//catch (Exception $e) {
// $response = new Response('An error occurred', 500);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment