Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
0876971e
Commit
0876971e
authored
Mar 23, 2012
by
Crell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor DrupalKernel to extend HttpKernel.
parent
d64072f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
36 deletions
+53
-36
core/lib/Drupal/Core/DrupalKernel.php
core/lib/Drupal/Core/DrupalKernel.php
+45
-35
index.php
index.php
+8
-1
No files found.
core/lib/Drupal/Core/DrupalKernel.php
View file @
0876971e
...
...
@@ -5,15 +5,14 @@
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\Routing\RequestContext
;
use
Symfony\Component\HttpKernel\HttpKernelInterface
;
use
Symfony\Component\HttpKernel\HttpKernel
;
use
Symfony\Component\HttpKernel\KernelEvents
;
use
Symfony\Component\HttpKernel\Controller\ControllerResolver
;
use
Symfony\Component\EventDispatcher\EventDispatcher
;
use
Symfony\Component\EventDispatcher\EventDispatcherInterface
;
use
Symfony\Component\EventDispatcher\Event
;
use
Symfony\Component\HttpKernel\Controller\ControllerResolverInterface
;
use
Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
;
use
Symfony\Component\HttpKernel\EventListener\RouterListener
;
use
Symfony\Component\HttpKernel\EventListener\ExceptionListener
;
use
Drupal\Core\EventSubscriber\HtmlSubscriber
;
use
Drupal\Core\EventSubscriber\JsonSubscriber
;
use
Drupal\Core\EventSubscriber\AccessSubscriber
;
...
...
@@ -31,7 +30,45 @@
/**
* The DrupalApp class is the core of Drupal itself.
*/
class
DrupalKernel
implements
HttpKernelInterface
{
class
DrupalKernel
extends
HttpKernel
{
protected
$dispatcher
;
protected
$resolver
;
/**
* Constructor
*
* @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance
* @param ControllerResolverInterface $resolver A ControllerResolverInterface instance
*
* @api
*/
public
function
__construct
(
EventDispatcherInterface
$dispatcher
,
ControllerResolverInterface
$resolver
)
{
parent
::
__construct
(
$dispatcher
,
$resolver
);
$this
->
dispatcher
=
$dispatcher
;
$this
->
resolver
=
$resolver
;
// @todo Make this extensible rather than just hard coding some.
// @todo Add a subscriber to handle other things, too, like our Ajax
// replacement system.
$this
->
dispatcher
->
addSubscriber
(
new
HtmlSubscriber
());
$this
->
dispatcher
->
addSubscriber
(
new
JsonSubscriber
());
$this
->
dispatcher
->
addSubscriber
(
new
AccessSubscriber
());
$this
->
dispatcher
->
addSubscriber
(
new
PathSubscriber
());
$this
->
dispatcher
->
addSubscriber
(
new
LegacyControllerSubscriber
());
// Some other form of error occured that wasn't handled by another kernel
// listener. That could mean that it's a method/mime-type/error
// combination that is not accounted for, or some other type of error.
// Either way, treat it as a server-level error and return an HTTP 500.
// By default, this will be an HTML-type response because that's a decent
// best guess if we don't know otherwise.
$this
->
dispatcher
->
addSubscriber
(
new
ExceptionListener
(
function
(
Exception
$e
)
{
return
new
Response
(
'A fatal error occurred: '
.
$e
->
getMessage
(),
500
);
}));
}
/**
*
...
...
@@ -41,32 +78,11 @@ class DrupalKernel implements HttpKernelInterface {
* The response object to return to the requesting user agent.
*/
function
handle
(
Request
$request
,
$type
=
self
::
MASTER_REQUEST
,
$catch
=
true
)
{
try
{
$dispatcher
=
$this
->
getDispatcher
();
if
(
$type
==
self
::
MASTER_REQUEST
)
{
$matcher
=
$this
->
getMatcher
(
$request
);
$dispatcher
->
addSubscriber
(
new
RouterListener
(
$matcher
));
$dispatcher
->
addSubscriber
(
new
AccessSubscriber
());
$dispatcher
->
addSubscriber
(
new
PathSubscriber
());
$dispatcher
->
addSubscriber
(
new
LegacyControllerSubscriber
());
$resolver
=
new
ControllerResolver
();
$kernel
=
new
HttpKernel
(
$dispatcher
,
$resolver
);
$response
=
$kernel
->
handle
(
$request
);
$this
->
dispatcher
->
addSubscriber
(
new
RouterListener
(
$matcher
));
}
catch
(
Exception
$e
)
{
// Some other form of error occured that wasn't handled by another kernel
// listener. That could mean that it's a method/mime-type/error
// combination that is not accounted for, or some other type of error.
// Either way, treat it as a server-level error and return an HTTP 500.
// By default, this will be an HTML-type response because that's a decent
// best guess if we don't know otherwise.
$response
=
new
Response
(
'A fatal error occurred: '
.
$e
->
getMessage
(),
500
);
}
return
$response
;
return
parent
::
handle
(
$request
,
$type
,
$catch
);
}
/**
...
...
@@ -80,13 +96,7 @@ function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) {
* @return EventDispatcher
*/
protected
function
getDispatcher
()
{
$dispatcher
=
new
EventDispatcher
();
// @todo Make this extensible rather than just hard coding some.
// @todo Add a subscriber to handle other things, too, like our Ajax
// replacement system.
$dispatcher
->
addSubscriber
(
new
HtmlSubscriber
());
$dispatcher
->
addSubscriber
(
new
JsonSubscriber
());
return
$dispatcher
;
}
...
...
index.php
View file @
0876971e
...
...
@@ -2,6 +2,9 @@
use
Drupal\Core\DrupalKernel
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\EventDispatcher\EventDispatcher
;
use
Symfony\Component\HttpKernel\Controller\ControllerResolver
;
/**
* @file
...
...
@@ -26,5 +29,9 @@
// A request object from the HTTPFoundation to tell us about the request.
$request
=
Request
::
createFromGlobals
();
$kernel
=
new
DrupalKernel
();
$dispatcher
=
new
EventDispatcher
();
$resolver
=
new
ControllerResolver
();
$kernel
=
new
DrupalKernel
(
$dispatcher
,
$resolver
);
$kernel
->
handle
(
$request
)
->
send
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment