Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ExceptionDetectNeedsInstallSubscriber.php

class ExceptionDetectNeedsInstallSubscriber

Exception handler to determine if an exception indicates an uninstalled site.

Hierarchy

  • class \Drupal\Core\EventSubscriber\ExceptionDetectNeedsInstallSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses \Drupal\Core\Installer\InstallerRedirectTrait

Expanded class hierarchy of ExceptionDetectNeedsInstallSubscriber

File

core/lib/Drupal/Core/EventSubscriber/ExceptionDetectNeedsInstallSubscriber.php, line 15

Namespace

Drupal\Core\EventSubscriber
View source
class ExceptionDetectNeedsInstallSubscriber implements EventSubscriberInterface {
    use InstallerRedirectTrait;
    
    /**
     * The default database connection.
     *
     * @var \Drupal\Core\Database\Connection
     */
    protected $connection;
    
    /**
     * Constructs a new ExceptionDetectNeedsInstallSubscriber.
     *
     * @param \Drupal\Core\Database\Connection $connection
     *   The default database connection.
     */
    public function __construct(Connection $connection) {
        $this->connection = $connection;
    }
    
    /**
     * Handles errors for this subscriber.
     *
     * @param \Symfony\Component\HttpKernel\Event\ExceptionEvent $event
     *   The event to process.
     */
    public function onException(ExceptionEvent $event) {
        $exception = $event->getThrowable();
        if ($this->shouldRedirectToInstaller($exception, $this->connection)) {
            // Only redirect if this is an HTML response (i.e., a user trying to view
            // the site in a web browser before installing it).
            $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',
                ]));
            }
        }
    }
    
    /**
     * Registers the methods in this class that should be listeners.
     *
     * @return array
     *   An array of event listener definitions.
     */
    public static function getSubscribedEvents() : array {
        $events[KernelEvents::EXCEPTION][] = [
            'onException',
            100,
        ];
        return $events;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ExceptionDetectNeedsInstallSubscriber::$connection protected property The default database connection.
ExceptionDetectNeedsInstallSubscriber::getSubscribedEvents public static function Registers the methods in this class that should be listeners. Overrides EventSubscriberInterface::getSubscribedEvents
ExceptionDetectNeedsInstallSubscriber::onException public function Handles errors for this subscriber.
ExceptionDetectNeedsInstallSubscriber::__construct public function Constructs a new ExceptionDetectNeedsInstallSubscriber.
InstallerRedirectTrait::isCli protected function Returns whether the current PHP process runs on CLI.
InstallerRedirectTrait::shouldRedirectToInstaller protected function Determines if an exception handler should redirect to the installer.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal