MaintenanceMode.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Drupal\Core\Site;
  3. use Drupal\Core\Routing\RouteMatchInterface;
  4. use Drupal\Core\Session\AccountInterface;
  5. use Drupal\Core\State\StateInterface;
  6. /**
  7. * Provides the default implementation of the maintenance mode service.
  8. */
  9. class MaintenanceMode implements MaintenanceModeInterface {
  10. /**
  11. * The state.
  12. *
  13. * @var \Drupal\Core\State\StateInterface
  14. */
  15. protected $state;
  16. /**
  17. * Constructs a new maintenance mode service.
  18. *
  19. * @param \Drupal\Core\State\StateInterface $state
  20. * The state.
  21. */
  22. public function __construct(StateInterface $state) {
  23. $this->state = $state;
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function applies(RouteMatchInterface $route_match) {
  29. if (!$this->state->get('system.maintenance_mode')) {
  30. return FALSE;
  31. }
  32. if ($route = $route_match->getRouteObject()) {
  33. if ($route->getOption('_maintenance_access')) {
  34. return FALSE;
  35. }
  36. }
  37. return TRUE;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function exempt(AccountInterface $account) {
  43. return $account->hasPermission('access site in maintenance mode');
  44. }
  45. }