From d15cf5883387a230aaf872fb726ded1b6f721e9f Mon Sep 17 00:00:00 2001
From: Bertus Steenberg <bertus.s@superbalist.com>
Date: Sun, 28 Apr 2019 12:23:20 +0200
Subject: [PATCH] config merge code from laravel 5

---
 src/PrometheusServiceProvider.php | 41 +++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/src/PrometheusServiceProvider.php b/src/PrometheusServiceProvider.php
index 018f997..1843a8e 100644
--- a/src/PrometheusServiceProvider.php
+++ b/src/PrometheusServiceProvider.php
@@ -3,6 +3,7 @@
 namespace Superbalist\LaravelPrometheusExporter;
 
 use Illuminate\Support\ServiceProvider;
+use Illuminate\Support\Arr;
 use Prometheus\CollectorRegistry;
 use Prometheus\Storage\Adapter;
 
@@ -69,4 +70,44 @@ class PrometheusServiceProvider extends ServiceProvider
             'prometheus.storage_adapter',
         ];
     }
+
+    /**
+     * https://medium.com/@koenhoeijmakers/properly-merging-configs-in-laravel-packages-a4209701746d
+     * :heart:
+     *
+     * Merge the given configuration with the existing configuration.
+     *
+     * @param  string  $path
+     * @param  string  $key
+     * @return void
+     */
+    protected function mergeConfigFrom($path, $key)
+    {
+        $config = $this->app['config']->get($key, []);
+        $this->app['config']->set($key, $this->mergeConfig(require $path, $config));
+    }
+    /**
+     * Merges the configs together and takes multi-dimensional arrays into account.
+     *
+     * @param  array  $original
+     * @param  array  $merging
+     * @return array
+     */
+    protected function mergeConfig(array $original, array $merging)
+    {
+        $array = array_merge($original, $merging);
+        foreach ($original as $key => $value) {
+            if (! is_array($value)) {
+                continue;
+            }
+            if (! Arr::exists($merging, $key)) {
+                continue;
+            }
+            if (is_numeric($key)) {
+                continue;
+            }
+            $array[$key] = $this->mergeConfig($value, $merging[$key]);
+        }
+        return $array;
+    }
 }