You are here

public function EnvironmentConfigOverride::loadOverrides in Config override 8

Returns config overrides.

Parameters

array $names: A list of configuration names that are being loaded.

Return value

array An array keyed by configuration name of override data. Override data contains a nested array structure of overrides.

Overrides ConfigFactoryOverrideInterface::loadOverrides

File

src/EnvironmentConfigOverride.php, line 46

Class

EnvironmentConfigOverride
Provides a config override which uses the environment variable.

Namespace

Drupal\config_override

Code

public function loadOverrides($names) {
  $config_overrides = [];
  foreach (array_intersect_key($this->environmentOverrides, array_flip($names)) as $config_name => $config) {
    foreach ($config as $config_key => $config_value) {
      $index = 'config___' . str_replace('.', '__', $config_name) . '___' . $config_key;
      if (($value = getenv($index)) && $value !== NULL) {
        $config_value = $value;
      }
      $uppercase_index = strtoupper($index);
      if (($value = getenv($uppercase_index)) && $value !== NULL) {
        $config_value = $value;
      }

      // The config value can be a json encoded object, which we will try to
      // take into account.
      $json_decode_result = json_decode($config_value, TRUE);
      if (!json_last_error()) {
        $config_value = $json_decode_result;
      }
      $config_overrides[$config_name][$config_key] = $config_value;
    }
  }
  return $config_overrides;
}