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