@@ -131,6 +131,32 @@ public function get($path = '')
131
131
return $ this ->getWithParts ($ path );
132
132
}
133
133
134
+ /**
135
+ * Merge newly loaded config data into already loaded.
136
+ *
137
+ * @param array $newData
138
+ * @return void
139
+ */
140
+ private function mergeData (array $ newData ): void
141
+ {
142
+ if (array_key_exists (ScopeInterface::SCOPE_DEFAULT , $ newData )) {
143
+ //Sometimes new data may contain links to arrays and we don't want that.
144
+ $ this ->data [ScopeInterface::SCOPE_DEFAULT ] = (array )$ newData [ScopeInterface::SCOPE_DEFAULT ];
145
+ unset($ newData [ScopeInterface::SCOPE_DEFAULT ]);
146
+ }
147
+ foreach ($ newData as $ scopeType => $ scopeTypeData ) {
148
+ if (!array_key_exists ($ scopeType , $ this ->data )) {
149
+ //Sometimes new data may contain links to arrays and we don't want that.
150
+ $ this ->data [$ scopeType ] = (array )$ scopeTypeData ;
151
+ } else {
152
+ foreach ($ scopeTypeData as $ scopeId => $ scopeData ) {
153
+ //Sometimes new data may contain links to arrays and we don't want that.
154
+ $ this ->data [$ scopeType ][$ scopeId ] = (array )$ scopeData ;
155
+ }
156
+ }
157
+ }
158
+ }
159
+
134
160
/**
135
161
* Proceed with parts extraction from path.
136
162
*
@@ -143,8 +169,10 @@ private function getWithParts($path)
143
169
144
170
if (count ($ pathParts ) === 1 && $ pathParts [0 ] !== ScopeInterface::SCOPE_DEFAULT ) {
145
171
if (!isset ($ this ->data [$ pathParts [0 ]])) {
172
+ //First filling data property with unprocessed data for post-processors to be able to use.
146
173
$ data = $ this ->readData ();
147
- $ this ->data = array_replace_recursive ($ this ->data , $ this ->postProcessor ->process ($ data ));
174
+ //Post-processing only the data we know is not yet processed.
175
+ $ this ->mergeData ($ this ->postProcessor ->process ($ data ));
148
176
}
149
177
150
178
return $ this ->data [$ pathParts [0 ]];
@@ -154,12 +182,11 @@ private function getWithParts($path)
154
182
155
183
if ($ scopeType === ScopeInterface::SCOPE_DEFAULT ) {
156
184
if (!isset ($ this ->data [$ scopeType ])) {
157
- $ this ->data = array_replace_recursive (
158
- $ this ->data ,
159
- $ scopeData = $ this ->loadDefaultScopeData ($ scopeType )
160
- );
185
+ //Adding unprocessed data to the data property so it can be used in post-processing.
186
+ $ this ->mergeData ($ scopeData = $ this ->loadDefaultScopeData ($ scopeType ));
187
+ //Only post-processing the data we know is raw.
161
188
$ scopeData = $ this ->postProcessor ->process ($ scopeData );
162
- $ this ->data = array_replace_recursive ( $ this -> data , $ scopeData );
189
+ $ this ->mergeData ( $ scopeData );
163
190
}
164
191
165
192
return $ this ->getDataByPathParts ($ this ->data [$ scopeType ], $ pathParts );
@@ -169,9 +196,11 @@ private function getWithParts($path)
169
196
170
197
if (!isset ($ this ->data [$ scopeType ][$ scopeId ])) {
171
198
$ scopeData = $ this ->loadScopeData ($ scopeType , $ scopeId );
172
- $ this ->data = array_replace_recursive ($ this ->data , $ scopeData );
199
+ //Adding unprocessed data to the data property so it can be used in post-processing.
200
+ $ this ->mergeData ($ scopeData );
201
+ //Only post-processing the data we know is raw.
173
202
$ scopeData = $ this ->postProcessor ->process ($ scopeData );
174
- $ this ->data = array_replace_recursive ( $ this -> data , $ scopeData );
203
+ $ this ->mergeData ( $ scopeData );
175
204
}
176
205
177
206
return isset ($ this ->data [$ scopeType ][$ scopeId ])
0 commit comments