DrupalKernel.php 2.73 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

namespace Drupal\Core;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\KernelEvents;
10
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
11
use Symfony\Component\EventDispatcher\Event;
12
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
13
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
14
use Symfony\Component\HttpKernel\EventListener\RouterListener;
15
use Symfony\Component\HttpKernel\EventListener\ExceptionListener;
16
use Drupal\Core\EventSubscriber\ViewSubscriber;
17
use Drupal\Core\EventSubscriber\AccessSubscriber;
18
use Drupal\Core\EventSubscriber\PathSubscriber;
19
use Drupal\Core\EventSubscriber\LegacyControllerSubscriber;
20

21
use Exception;
22
23
24
25

/**
 * @file
 *
Crell's avatar
Crell committed
26
 * Definition of Drupal\Core\DrupalKernel.
27
28
29
 */

/**
Crell's avatar
Crell committed
30
 * The DrupalApp class is the core of Drupal itself.
31
 */
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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;

50
51
52
53
      $context = new RequestContext();
      $this->matcher = new UrlMatcher($context);
      $this->dispatcher->addSubscriber(new RouterListener($this->matcher));

54
55
      $negotiation = new ContentNegotiation();

56
57
58
      // @todo Make this extensible rather than just hard coding some.
      // @todo Add a subscriber to handle other things, too, like our Ajax
      // replacement system.
59
      $this->dispatcher->addSubscriber(new ViewSubscriber($negotiation));
60
61
62
63
64
65
66
67
68
69
      $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.
70
      $this->dispatcher->addSubscriber(new ExceptionListener(array(new ExceptionController($this, $negotiation), 'execute')));
71
72
    }
}