@@ -36,12 +36,12 @@ class System implements ConfigTypeInterface
36
36
/**
37
37
* Config cache tag.
38
38
*/
39
- const CACHE_TAG = 'config_scopes ' ;
39
+ public const CACHE_TAG = 'config_scopes ' ;
40
40
41
41
/**
42
42
* System config type.
43
43
*/
44
- const CONFIG_TYPE = 'system ' ;
44
+ public const CONFIG_TYPE = 'system ' ;
45
45
46
46
/**
47
47
* @var string
@@ -173,8 +173,7 @@ public function __construct(
173
173
public function get ($ path = '' )
174
174
{
175
175
if ($ path === '' ) {
176
- $ this ->data = array_replace_recursive ($ this ->loadAllData (), $ this ->data );
177
-
176
+ $ this ->data = $ this ->loadAllData ();
178
177
return $ this ->data ;
179
178
}
180
179
@@ -193,8 +192,7 @@ private function getWithParts($path)
193
192
194
193
if (count ($ pathParts ) === 1 && $ pathParts [0 ] !== ScopeInterface::SCOPE_DEFAULT ) {
195
194
if (!isset ($ this ->data [$ pathParts [0 ]])) {
196
- $ data = $ this ->readData ();
197
- $ this ->data = array_replace_recursive ($ data , $ this ->data );
195
+ $ this ->readData ();
198
196
}
199
197
200
198
return $ this ->data [$ pathParts [0 ]];
@@ -204,7 +202,8 @@ private function getWithParts($path)
204
202
205
203
if ($ scopeType === ScopeInterface::SCOPE_DEFAULT ) {
206
204
if (!isset ($ this ->data [$ scopeType ])) {
207
- $ this ->data = array_replace_recursive ($ this ->loadDefaultScopeData ($ scopeType ), $ this ->data );
205
+ $ scopeData = $ this ->loadDefaultScopeData () ?? [];
206
+ $ this ->setDataByScopeType ($ scopeType , $ scopeData );
208
207
}
209
208
210
209
return $ this ->getDataByPathParts ($ this ->data [$ scopeType ], $ pathParts );
@@ -213,11 +212,8 @@ private function getWithParts($path)
213
212
$ scopeId = array_shift ($ pathParts );
214
213
215
214
if (!isset ($ this ->data [$ scopeType ][$ scopeId ])) {
216
- $ scopeData = $ this ->loadScopeData ($ scopeType , $ scopeId );
217
-
218
- if (!isset ($ this ->data [$ scopeType ][$ scopeId ])) {
219
- $ this ->data = array_replace_recursive ($ scopeData , $ this ->data );
220
- }
215
+ $ scopeData = $ this ->loadScopeData ($ scopeType , $ scopeId ) ?? [];
216
+ $ this ->setDataByScopeId ($ scopeType , $ scopeId , $ scopeData );
221
217
}
222
218
223
219
return isset ($ this ->data [$ scopeType ][$ scopeId ])
@@ -256,16 +252,16 @@ private function loadAllData()
256
252
/**
257
253
* Load configuration data for default scope.
258
254
*
259
- * @param string $scopeType
260
255
* @return array
261
256
*/
262
- private function loadDefaultScopeData ($ scopeType )
257
+ private function loadDefaultScopeData ()
263
258
{
264
259
if (!$ this ->cacheState ->isEnabled (Config::TYPE_IDENTIFIER )) {
265
260
return $ this ->readData ();
266
261
}
267
262
268
- $ loadAction = function () use ($ scopeType ) {
263
+ $ loadAction = function () {
264
+ $ scopeType = ScopeInterface::SCOPE_DEFAULT ;
269
265
$ cachedData = $ this ->cache ->load ($ this ->configType . '_ ' . $ scopeType );
270
266
$ scopeData = false ;
271
267
if ($ cachedData !== false ) {
@@ -325,6 +321,35 @@ private function loadScopeData($scopeType, $scopeId)
325
321
);
326
322
}
327
323
324
+ /**
325
+ * Sets data according to scope type.
326
+ *
327
+ * @param string|null $scopeType
328
+ * @param array $scopeData
329
+ * @return void
330
+ */
331
+ private function setDataByScopeType (?string $ scopeType , array $ scopeData ): void
332
+ {
333
+ if (!isset ($ this ->data [$ scopeType ]) && isset ($ scopeData [$ scopeType ])) {
334
+ $ this ->data [$ scopeType ] = $ scopeData [$ scopeType ];
335
+ }
336
+ }
337
+
338
+ /**
339
+ * Sets data according to scope type and id.
340
+ *
341
+ * @param string|null $scopeType
342
+ * @param string|null $scopeId
343
+ * @param array $scopeData
344
+ * @return void
345
+ */
346
+ private function setDataByScopeId (?string $ scopeType , ?string $ scopeId , array $ scopeData ): void
347
+ {
348
+ if (!isset ($ this ->data [$ scopeType ][$ scopeId ]) && isset ($ scopeData [$ scopeType ][$ scopeId ])) {
349
+ $ this ->data [$ scopeType ][$ scopeId ] = $ scopeData [$ scopeType ][$ scopeId ];
350
+ }
351
+ }
352
+
328
353
/**
329
354
* Cache configuration data.
330
355
*
0 commit comments