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