Commit f9fe640f authored by Crell's avatar Crell
Browse files

Move the new routing logic into a DrupalKernel object.

parent de774078
......@@ -5091,7 +5091,6 @@ function _drupal_bootstrap_full() {
require_once DRUPAL_ROOT . '/core/includes/theme.inc';
require_once DRUPAL_ROOT . '/core/includes/pager.inc';
require_once DRUPAL_ROOT . '/' . variable_get('menu_inc', 'core/includes/menu.inc');
require_once DRUPAL_ROOT . '/core/includes/router.inc';
require_once DRUPAL_ROOT . '/core/includes/tablesort.inc';
require_once DRUPAL_ROOT . '/core/includes/file.inc';
require_once DRUPAL_ROOT . '/core/includes/unicode.inc';
......
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;
use Drupal\Core\UrlMatcher;
/**
* Execute the page callback associated with given request.
*
* @param Request $request
* The Symfony Request object used to determine what will be executed.
* @return Response
* A Symfony Response object describing the response to deliver to the client.
*/
function router_execute_request(Request $request) {
try {
// Resolve a routing context(path, etc) using the routes object to a
// Set a routing context to translate.
$context = new RequestContext();
$context->fromRequest($request);
$matcher = new UrlMatcher($context);
// Push path paramaters into attributes.
$request->attributes->add($matcher->match($request->getPathInfo()));
// Get the controller(page callback) from the resolver.
$resolver = new ControllerResolver();
$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);
return $kernel->handle($request);
}
catch (ResourceNotFoundException $e) {
$response = new Response('Not Found', 404);
}
//catch (Exception $e) {
// $response = new Response('An error occurred', 500);
//}
return $response;
}
<?php
namespace Drupal\Core;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;
/**
* @file
*
* Definition of Drupal\Core\DrupalKernel.
*/
/**
* The DrupalKernel is the main routing and dispatching routine in Drupal.
*/
class DrupalKernel implements HttpKernelInterface {
function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) {
try {
// Resolve a routing context(path, etc) using the routes object to a
// Set a routing context to translate.
$context = new RequestContext();
$context->fromRequest($request);
$matcher = new UrlMatcher($context);
// Push path paramaters into attributes.
$request->attributes->add($matcher->match($request->getPathInfo()));
// Get the controller(page callback) from the resolver.
$resolver = new ControllerResolver();
$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);
return $kernel->handle($request);
}
catch (ResourceNotFoundException $e) {
$response = new Response('Not Found', 404);
}
//catch (Exception $e) {
// $response = new Response('An error occurred', 500);
//}
return $response;
}
}
<?php
use Drupal\Core\DrupalKernel;
/**
* @file
* The PHP page that serves all page requests on a Drupal installation.
......@@ -24,7 +26,10 @@
// A request object from the HTTPFoundation to tell us about the request.
$request = Request::createFromGlobals();
// Run our router, get a response.
$response = router_execute_request($request);
// Run our kernel, get a response, and send it.
$kernel = new DrupalKernel();
$kernel->handle($request)->send();
//$response = router_execute_request($request);
// Output response.
$response->send();
//$response->send();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment