Mercurial > hg > isophonics-drupal-site
diff core/lib/Drupal/Core/Site/MaintenanceMode.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/lib/Drupal/Core/Site/MaintenanceMode.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,55 @@ +<?php + +namespace Drupal\Core\Site; + +use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Session\AccountInterface; +use Drupal\Core\State\StateInterface; + +/** + * Provides the default implementation of the maintenance mode service. + */ +class MaintenanceMode implements MaintenanceModeInterface { + + /** + * The state. + * + * @var \Drupal\Core\State\StateInterface + */ + protected $state; + + /** + * Constructs a new maintenance mode service. + * + * @param \Drupal\Core\State\StateInterface $state + * The state. + */ + public function __construct(StateInterface $state) { + $this->state = $state; + } + + /** + * {@inheritdoc} + */ + public function applies(RouteMatchInterface $route_match) { + if (!$this->state->get('system.maintenance_mode')) { + return FALSE; + } + + if ($route = $route_match->getRouteObject()) { + if ($route->getOption('_maintenance_access')) { + return FALSE; + } + } + + return TRUE; + } + + /** + * {@inheritdoc} + */ + public function exempt(AccountInterface $account) { + return $account->hasPermission('access site in maintenance mode'); + } + +}