You are here

public function ConfigDiffTransformer::reverseTransform in Update helper 8

Same name and namespace in other branches
  1. 2.x src/ConfigDiffTransformer.php \Drupal\update_helper\ConfigDiffTransformer::reverseTransform()

Reverse transformation of diff.

Parameters

array $config_string_lines: String configuration lines.

Return value

array Nested configuration array.

File

src/ConfigDiffTransformer.php, line 68

Class

ConfigDiffTransformer
Config transformer for configuration diffing.

Namespace

Drupal\update_helper

Code

public function reverseTransform(array $config_string_lines) {
  $result = [];
  foreach ($config_string_lines as $row) {
    $key_value = explode(' : ', $row);
    $key_path = explode('::', $key_value[0]);
    $last_key = array_pop($key_path);
    $current_element =& $result;
    foreach ($key_path as $key) {
      if ($key === '-') {
        $key = count($current_element) - 1;
      }
      elseif (!isset($current_element[$key])) {
        $current_element[$key] = [];
      }
      $current_element =& $current_element[$key];
    }
    $value = [];
    if (count($key_value) === 2) {
      $value = $this
        ->unstringifyValue($key_value[1]);
    }
    if ($last_key === '-') {
      $current_element[] = $value;
    }
    else {
      $current_element[$last_key] = $value;
    }
  }
  return $result;
}