@@ -66,7 +66,7 @@ private function setVendorConfig(){
6666 $ vendor_config = require $ path ;
6767 $ config = $ this ->app ['config ' ]->get ($ config_key , []);
6868
69- $ this ->app ['config ' ]->set ($ config_key , array_merge ($ vendor_config , $ config ));
69+ $ this ->app ['config ' ]->set ($ config_key , $ this -> array_merge_recursive_distinct ($ vendor_config , $ config ));
7070
7171 $ config = $ this ->app ['config ' ]->get ($ config_key );
7272
@@ -90,4 +90,56 @@ private function setVendorConfig(){
9090
9191 $ this ->app ['config ' ]->set ($ config_key , $ config );
9292 }
93+
94+ /**
95+ * Marge arrays recursively and distinct
96+ *
97+ * Merges any number of arrays / parameters recursively, replacing
98+ * entries with string keys with values from latter arrays.
99+ * If the entry or the next value to be assigned is an array, then it
100+ * automatically treats both arguments as an array.
101+ * Numeric entries are appended, not replaced, but only if they are
102+ * unique
103+ *
104+ * @param array $array1 Initial array to merge.
105+ * @param array ... Variable list of arrays to recursively merge.
106+ *
107+ * @return array|mixed
108+ *
109+ * @link http://www.php.net/manual/en/function.array-merge-recursive.php#96201
110+ * @author Mark Roduner <[email protected] > 111+ */
112+ private function array_merge_recursive_distinct () {
113+
114+ $ arrays = func_get_args ();
115+ $ base = array_shift ($ arrays );
116+
117+ if (!is_array ($ base )) $ base = empty ($ base ) ? array () : array ($ base );
118+
119+ foreach ($ arrays as $ append ) {
120+
121+ if (!is_array ($ append )) $ append = array ($ append );
122+
123+ foreach ($ append as $ key => $ value ) {
124+
125+ if (!array_key_exists ($ key , $ base ) and !is_numeric ($ key )) {
126+ $ base [$ key ] = $ append [$ key ];
127+ continue ;
128+ }
129+
130+ if (is_array ($ value ) or is_array ($ base [$ key ])) {
131+ $ base [$ key ] = $ this ->array_merge_recursive_distinct ($ base [$ key ], $ append [$ key ]);
132+ } else if (is_numeric ($ key )) {
133+ if (!in_array ($ value , $ base )) $ base [] = $ value ;
134+ } else {
135+ $ base [$ key ] = $ value ;
136+ }
137+
138+ }
139+
140+ }
141+
142+ return $ base ;
143+ }
144+
93145}
0 commit comments