Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/EventSubscriber/ExceptionDetectNeedsInstallSubscriber.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\EventSubscriber; | |
4 | |
5 use Drupal\Core\Database\Connection; | |
6 use Drupal\Core\Installer\InstallerRedirectTrait; | |
7 use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
8 use Symfony\Component\HttpFoundation\RedirectResponse; | |
9 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; | |
10 use Symfony\Component\HttpKernel\KernelEvents; | |
11 | |
12 /** | |
13 * Exception handler to determine if an exception indicates an uninstalled site. | |
14 */ | |
15 class ExceptionDetectNeedsInstallSubscriber implements EventSubscriberInterface { | |
16 use InstallerRedirectTrait; | |
17 | |
18 /** | |
19 * The default database connection. | |
20 * | |
21 * @var \Drupal\Core\Database\Connection | |
22 */ | |
23 protected $connection; | |
24 | |
25 /** | |
26 * Constructs a new ExceptionDetectNeedsInstallSubscriber. | |
27 * | |
28 * @param \Drupal\Core\Database\Connection $connection | |
29 * The default database connection. | |
30 */ | |
31 public function __construct(Connection $connection) { | |
32 $this->connection = $connection; | |
33 } | |
34 | |
35 /** | |
36 * Handles errors for this subscriber. | |
37 * | |
38 * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event | |
39 * The event to process. | |
40 */ | |
41 public function onException(GetResponseForExceptionEvent $event) { | |
42 $exception = $event->getException(); | |
43 if ($this->shouldRedirectToInstaller($exception, $this->connection)) { | |
44 // Only redirect if this is an HTML response (i.e., a user trying to view | |
45 // the site in a web browser before installing it). | |
46 $request = $event->getRequest(); | |
47 $format = $request->query->get(MainContentViewSubscriber::WRAPPER_FORMAT, $request->getRequestFormat()); | |
48 if ($format == 'html') { | |
49 $event->setResponse(new RedirectResponse($request->getBasePath() . '/core/install.php', 302, ['Cache-Control' => 'no-cache'])); | |
50 } | |
51 } | |
52 } | |
53 | |
54 /** | |
55 * Registers the methods in this class that should be listeners. | |
56 * | |
57 * @return array | |
58 * An array of event listener definitions. | |
59 */ | |
60 public static function getSubscribedEvents() { | |
61 $events[KernelEvents::EXCEPTION][] = ['onException', 100]; | |
62 return $events; | |
63 } | |
64 | |
65 } |