ExceptionDetectNeedsInstallSubscriber.php in Drupal 9
File
core/lib/Drupal/Core/EventSubscriber/ExceptionDetectNeedsInstallSubscriber.php
View source
<?php
namespace Drupal\Core\EventSubscriber;
use Drupal\Core\Database\Connection;
use Drupal\Core\Installer\InstallerRedirectTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class ExceptionDetectNeedsInstallSubscriber implements EventSubscriberInterface {
use InstallerRedirectTrait;
protected $connection;
public function __construct(Connection $connection) {
$this->connection = $connection;
}
public function onException(ExceptionEvent $event) {
$exception = $event
->getThrowable();
if ($this
->shouldRedirectToInstaller($exception, $this->connection)) {
$request = $event
->getRequest();
$format = $request->query
->get(MainContentViewSubscriber::WRAPPER_FORMAT, $request
->getRequestFormat());
if ($format == 'html') {
$event
->setResponse(new RedirectResponse($request
->getBasePath() . '/core/install.php', 302, [
'Cache-Control' => 'no-cache',
]));
}
}
}
public static function getSubscribedEvents() {
$events[KernelEvents::EXCEPTION][] = [
'onException',
100,
];
return $events;
}
}