You are here

public function EnvironmentSubscriber::checkForEnvironmentSwitch in Environment 8

File

src/EventSubscriber/EnvironmentSubscriber.php, line 10

Class

EnvironmentSubscriber

Namespace

Drupal\environment\EventSubscriber

Code

public function checkForEnvironmentSwitch(GetResponseEvent $event) {
  $env_req_override = \Drupal::config('environment.settings')
    ->get('environment_require_override');
  if ($env_req_override) {
    $env_override = \Drupal::config('environment.settings')
      ->get('environment_override');
    if (!empty($env_override)) {
      $current_env = environment_current(FALSE);
      if ($current_env != $env_override) {
        environment_switch($env_override, TRUE);
      }
    }
  }
}