Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / consolidation / config / src / Util / ConfigOverlay.php
index d1f12697742fdff20b6954b5ef89aa61c1d51877..2257ef615ca88a3bfbf98da08bb30b1cb6f6e3e3 100644 (file)
@@ -3,6 +3,9 @@ namespace Consolidation\Config\Util;
 
 use Consolidation\Config\Config;
 use Consolidation\Config\ConfigInterface;
+use Consolidation\Config\Util\ArrayUtil;
+use Consolidation\Config\Util\ConfigInterpolatorInterface;
+use Consolidation\Config\Util\ConfigInterpolatorTrait;
 
 /**
  * Overlay different configuration objects that implement ConfigInterface
@@ -12,8 +15,9 @@ use Consolidation\Config\ConfigInterface;
  * individual configuration context. When using overlays, always call
  * getDefault / setDefault on the ConfigOverlay object itself.
  */
-class ConfigOverlay implements ConfigInterface
+class ConfigOverlay implements ConfigInterface, ConfigInterpolatorInterface
 {
+    use ConfigInterpolatorTrait;
     protected $contexts = [];
 
     const DEFAULT_CONTEXT = 'default';
@@ -115,6 +119,14 @@ class ConfigOverlay implements ConfigInterface
      * @inheritdoc
      */
     public function get($key, $default = null)
+    {
+        if (is_array($default)) {
+            return $this->getUnion($key);
+        }
+        return $this->getSingle($key, $default);
+    }
+
+    public function getSingle($key, $default = null)
     {
         $context = $this->findContext($key);
         if ($context) {
@@ -123,6 +135,18 @@ class ConfigOverlay implements ConfigInterface
         return $default;
     }
 
+    public function getUnion($key)
+    {
+        $result = [];
+        foreach (array_reverse($this->contexts) as $name => $config) {
+            $item = (array) $config->get($key, []);
+            if ($item !== null) {
+                $result = array_merge($result, $item);
+            }
+        }
+        return $result;
+    }
+
     /**
      * @inheritdoc
      */
@@ -171,7 +195,8 @@ class ConfigOverlay implements ConfigInterface
     {
         $export = [];
         foreach ($this->contexts as $name => $config) {
-            $export = array_merge_recursive($export, $config->export());
+            $exportToMerge = $config->export();
+            $export = \array_replace_recursive($export, $exportToMerge);
         }
         return $export;
     }