core/includes/common.inc | 4 +- .../Core/DependencyInjection/ContainerBuilder.php | 58 +++++++++++++++++ core/lib/Drupal/Core/DrupalKernel.php | 65 -------------------- core/lib/Drupal/Core/ExceptionController.php | 3 +- index.php | 8 +-- 5 files changed, 63 insertions(+), 75 deletions(-) diff --git a/core/includes/common.inc b/core/includes/common.inc index 15c54d3..8657c6d 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -5067,9 +5067,9 @@ function _drupal_bootstrap_code() { } /** - * Temporary BC function for scripts not using DrupalKernel. + * Temporary BC function for scripts not using HttpKernel. * - * DrupalKernel skips this and replicates it via event listeners. + * HttpKernel skips this and replicates it via event listeners. * * @see Drupal\Core\EventSubscriber\PathSubscriber; * @see Drupal\Core\EventSubscriber\LegacyRequestSubscriber; diff --git a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php index aa73ace..db29a30 100644 --- a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php +++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php @@ -7,7 +7,24 @@ namespace Drupal\Core\DependencyInjection; +use Drupal\Core\ContentNegotiation; +use Drupal\Core\EventSubscriber\AccessSubscriber; +use Drupal\Core\EventSubscriber\FinishResponseSubscriber; +use Drupal\Core\EventSubscriber\LegacyControllerSubscriber; +use Drupal\Core\EventSubscriber\LegacyRequestSubscriber; +use Drupal\Core\EventSubscriber\MaintenanceModeSubscriber; +use Drupal\Core\EventSubscriber\PathSubscriber; +use Drupal\Core\EventSubscriber\RequestCloseSubscriber; +use Drupal\Core\EventSubscriber\RouterListener; +use Drupal\Core\EventSubscriber\ViewSubscriber; +use Drupal\Core\ExceptionController; +use Drupal\Core\LegacyUrlMatcher; use Symfony\Component\DependencyInjection\ContainerBuilder as BaseContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\HttpKernel\Controller\ControllerResolver; +use Symfony\Component\HttpKernel\EventListener\ExceptionListener; +use Symfony\Component\HttpKernel\HttpKernel; /** * Drupal's dependency injection container. @@ -27,5 +44,46 @@ class ContainerBuilder extends BaseContainerBuilder { // Register the default language content. $this->register(LANGUAGE_TYPE_CONTENT, 'Drupal\\Core\\Language\\Language'); + + $this->setDefinition('kernel', new Definition('Symfony\Component\HttpKernel\HttpKernel')) + ->setFactoryClass('Drupal\Core\DependencyInjection\ContainerBuilder') + ->setFactoryMethod('getKernel'); + } + + /** + * Creates the HttpKernel. Factory method. + */ + public static function getKernel() { + $dispatcher = new EventDispatcher(); + $resolver = new ControllerResolver(); + + $kernel = new HttpKernel($dispatcher, $resolver); + + $matcher = new LegacyUrlMatcher(); + $dispatcher->addSubscriber(new RouterListener($matcher)); + + $negotiation = new ContentNegotiation(); + + // @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 ViewSubscriber($negotiation)); + $dispatcher->addSubscriber(new AccessSubscriber()); + $dispatcher->addSubscriber(new MaintenanceModeSubscriber()); + $dispatcher->addSubscriber(new PathSubscriber()); + $dispatcher->addSubscriber(new LegacyRequestSubscriber()); + $dispatcher->addSubscriber(new LegacyControllerSubscriber()); + $dispatcher->addSubscriber(new FinishResponseSubscriber()); + $dispatcher->addSubscriber(new RequestCloseSubscriber()); + + // 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. + $dispatcher->addSubscriber(new ExceptionListener(array(new ExceptionController($kernel, $negotiation), 'execute'))); + + return $kernel; } } diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php deleted file mode 100644 index 7361a82..0000000 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ /dev/null @@ -1,65 +0,0 @@ -matcher = new LegacyUrlMatcher(); - $this->dispatcher->addSubscriber(new RouterListener($this->matcher)); - - $negotiation = new ContentNegotiation(); - - // @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 ViewSubscriber($negotiation)); - $this->dispatcher->addSubscriber(new AccessSubscriber()); - $this->dispatcher->addSubscriber(new MaintenanceModeSubscriber()); - $this->dispatcher->addSubscriber(new PathSubscriber()); - $this->dispatcher->addSubscriber(new LegacyRequestSubscriber()); - $this->dispatcher->addSubscriber(new LegacyControllerSubscriber()); - $this->dispatcher->addSubscriber(new FinishResponseSubscriber()); - $this->dispatcher->addSubscriber(new RequestCloseSubscriber()); - - // 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(array(new ExceptionController($this, $negotiation), 'execute'))); - } -} diff --git a/core/lib/Drupal/Core/ExceptionController.php b/core/lib/Drupal/Core/ExceptionController.php index b163395..9f836e6 100644 --- a/core/lib/Drupal/Core/ExceptionController.php +++ b/core/lib/Drupal/Core/ExceptionController.php @@ -10,6 +10,7 @@ namespace Drupal\Core; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Exception\FlattenException; @@ -119,7 +120,7 @@ class ExceptionController { drupal_static_reset('menu_set_active_trail'); menu_reset_static_cache(); - $response = $this->kernel->handle($subrequest, DrupalKernel::SUB_REQUEST); + $response = $this->kernel->handle($subrequest, HttpKernel::SUB_REQUEST); $response->setStatusCode(403, 'Access denied'); } else { diff --git a/index.php b/index.php index 2f05bb3..7d1a377 100644 --- a/index.php +++ b/index.php @@ -11,10 +11,7 @@ * See COPYRIGHT.txt and LICENSE.txt files in the "core" directory. */ -use Drupal\Core\DrupalKernel; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\EventDispatcher\EventDispatcher; -use Symfony\Component\HttpKernel\Controller\ControllerResolver; /** * Root directory of Drupal installation. @@ -39,9 +36,6 @@ request($request); // @see Drupal\Core\EventSubscriber\LegacyRequestSubscriber; drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE); -$dispatcher = new EventDispatcher(); -$resolver = new ControllerResolver(); - -$kernel = new DrupalKernel($dispatcher, $resolver); +$kernel = drupal_container()->get('kernel'); $response = $kernel->handle($request)->prepare($request)->send(); $kernel->terminate($request, $response);