5
5
*/
6
6
namespace Magento \Config \App \Config \Type ;
7
7
8
+ use Magento \Framework \App \Config \ConfigSourceInterface ;
8
9
use Magento \Framework \App \Config \ConfigTypeInterface ;
10
+ use Magento \Framework \App \Config \Spi \PostProcessorInterface ;
11
+ use Magento \Framework \App \Config \Spi \PreProcessorInterface ;
9
12
use Magento \Framework \App \ObjectManager ;
10
13
use Magento \Config \App \Config \Type \System \Reader ;
14
+ use Magento \Framework \App \ScopeInterface ;
15
+ use Magento \Framework \Cache \FrontendInterface ;
16
+ use Magento \Framework \Serialize \SerializerInterface ;
17
+ use Magento \Store \Model \Config \Processor \Fallback ;
18
+ use Magento \Store \Model \ScopeInterface as StoreScope ;
11
19
12
20
/**
13
21
* System configuration type
22
+ *
14
23
* @api
15
24
* @since 100.1.2
16
25
*/
17
26
class System implements ConfigTypeInterface
18
27
{
19
28
const CACHE_TAG = 'config_scopes ' ;
20
-
21
29
const CONFIG_TYPE = 'system ' ;
22
30
23
- /**
24
- * @var \Magento\Framework\App\Config\ConfigSourceInterface
25
- */
26
- private $ source ;
27
-
28
31
/**
29
32
* @var array
30
33
*/
31
34
private $ data = [];
32
35
33
36
/**
34
- * @var \Magento\Framework\App\Config\Spi\ PostProcessorInterface
37
+ * @var PostProcessorInterface
35
38
*/
36
39
private $ postProcessor ;
37
40
38
41
/**
39
- * @var \Magento\Framework\App\Config\Spi\PreProcessorInterface
40
- */
41
- private $ preProcessor ;
42
-
43
- /**
44
- * @var \Magento\Framework\Cache\FrontendInterface
42
+ * @var FrontendInterface
45
43
*/
46
44
private $ cache ;
47
45
48
46
/**
49
- * @var int
50
- */
51
- private $ cachingNestedLevel ;
52
-
53
- /**
54
- * @var \Magento\Store\Model\Config\Processor\Fallback
55
- */
56
- private $ fallback ;
57
-
58
- /**
59
- * @var \Magento\Framework\Serialize\SerializerInterface
47
+ * @var SerializerInterface
60
48
*/
61
49
private $ serializer ;
62
50
@@ -79,36 +67,34 @@ class System implements ConfigTypeInterface
79
67
*
80
68
* @var array
81
69
*/
82
- private $ availableDataScopes = null ;
70
+ private $ availableDataScopes ;
83
71
84
72
/**
85
- * @param \Magento\Framework\App\Config\ ConfigSourceInterface $source
86
- * @param \Magento\Framework\App\Config\Spi\ PostProcessorInterface $postProcessor
87
- * @param \Magento\Store\Model\Config\Processor\ Fallback $fallback
88
- * @param \Magento\Framework\Cache\ FrontendInterface $cache
89
- * @param \Magento\Framework\Serialize\ SerializerInterface $serializer
90
- * @param \Magento\Framework\App\Config\Spi\ PreProcessorInterface $preProcessor
73
+ * @param ConfigSourceInterface $source
74
+ * @param PostProcessorInterface $postProcessor
75
+ * @param Fallback $fallback
76
+ * @param FrontendInterface $cache
77
+ * @param SerializerInterface $serializer
78
+ * @param PreProcessorInterface $preProcessor
91
79
* @param int $cachingNestedLevel
92
80
* @param string $configType
93
81
* @param Reader $reader
82
+ *
83
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
94
84
*/
95
85
public function __construct (
96
- \ Magento \ Framework \ App \ Config \ ConfigSourceInterface $ source ,
97
- \ Magento \ Framework \ App \ Config \ Spi \ PostProcessorInterface $ postProcessor ,
98
- \ Magento \ Store \ Model \ Config \ Processor \ Fallback $ fallback ,
99
- \ Magento \ Framework \ Cache \ FrontendInterface $ cache ,
100
- \ Magento \ Framework \ Serialize \ SerializerInterface $ serializer ,
101
- \ Magento \ Framework \ App \ Config \ Spi \ PreProcessorInterface $ preProcessor ,
86
+ ConfigSourceInterface $ source ,
87
+ PostProcessorInterface $ postProcessor ,
88
+ Fallback $ fallback ,
89
+ FrontendInterface $ cache ,
90
+ SerializerInterface $ serializer ,
91
+ PreProcessorInterface $ preProcessor ,
102
92
$ cachingNestedLevel = 1 ,
103
93
$ configType = self ::CONFIG_TYPE ,
104
94
Reader $ reader = null
105
95
) {
106
- $ this ->source = $ source ;
107
96
$ this ->postProcessor = $ postProcessor ;
108
- $ this ->preProcessor = $ preProcessor ;
109
97
$ this ->cache = $ cache ;
110
- $ this ->cachingNestedLevel = $ cachingNestedLevel ;
111
- $ this ->fallback = $ fallback ;
112
98
$ this ->serializer = $ serializer ;
113
99
$ this ->configType = $ configType ;
114
100
$ this ->reader = $ reader ?: ObjectManager::getInstance ()->get (Reader::class);
@@ -136,27 +122,52 @@ public function get($path = '')
136
122
{
137
123
if ($ path === '' ) {
138
124
$ this ->data = array_replace_recursive ($ this ->loadAllData (), $ this ->data );
125
+
139
126
return $ this ->data ;
140
127
}
128
+
129
+ return $ this ->getWithParts ($ path );
130
+ }
131
+
132
+ /**
133
+ * Proceed with parts extraction from path.
134
+ *
135
+ * @param string $path
136
+ * @return array|int|string|boolean
137
+ */
138
+ private function getWithParts ($ path )
139
+ {
141
140
$ pathParts = explode ('/ ' , $ path );
142
- if (count ($ pathParts ) === 1 && $ pathParts [0 ] !== 'default ' ) {
141
+
142
+ if (count ($ pathParts ) === 1 && $ pathParts [0 ] !== ScopeInterface::SCOPE_DEFAULT ) {
143
143
if (!isset ($ this ->data [$ pathParts [0 ]])) {
144
144
$ data = $ this ->readData ();
145
145
$ this ->data = array_replace_recursive ($ data , $ this ->data );
146
146
}
147
+
147
148
return $ this ->data [$ pathParts [0 ]];
148
149
}
150
+
149
151
$ scopeType = array_shift ($ pathParts );
150
- if ($ scopeType === 'default ' ) {
152
+
153
+ if ($ scopeType === ScopeInterface::SCOPE_DEFAULT ) {
151
154
if (!isset ($ this ->data [$ scopeType ])) {
152
155
$ this ->data = array_replace_recursive ($ this ->loadDefaultScopeData ($ scopeType ), $ this ->data );
153
156
}
157
+
154
158
return $ this ->getDataByPathParts ($ this ->data [$ scopeType ], $ pathParts );
155
159
}
160
+
156
161
$ scopeId = array_shift ($ pathParts );
162
+
157
163
if (!isset ($ this ->data [$ scopeType ][$ scopeId ])) {
158
- $ this ->data = array_replace_recursive ($ this ->loadScopeData ($ scopeType , $ scopeId ), $ this ->data );
164
+ $ scopeData = $ this ->loadScopeData ($ scopeType , $ scopeId );
165
+
166
+ if (!isset ($ this ->data [$ scopeType ][$ scopeId ])) {
167
+ $ this ->data = array_replace_recursive ($ scopeData , $ this ->data );
168
+ }
159
169
}
170
+
160
171
return isset ($ this ->data [$ scopeType ][$ scopeId ])
161
172
? $ this ->getDataByPathParts ($ this ->data [$ scopeType ][$ scopeId ], $ pathParts )
162
173
: null ;
@@ -170,11 +181,13 @@ public function get($path = '')
170
181
private function loadAllData ()
171
182
{
172
183
$ cachedData = $ this ->cache ->load ($ this ->configType );
184
+
173
185
if ($ cachedData === false ) {
174
186
$ data = $ this ->readData ();
175
187
} else {
176
188
$ data = $ this ->serializer ->unserialize ($ cachedData );
177
189
}
190
+
178
191
return $ data ;
179
192
}
180
193
@@ -187,12 +200,14 @@ private function loadAllData()
187
200
private function loadDefaultScopeData ($ scopeType )
188
201
{
189
202
$ cachedData = $ this ->cache ->load ($ this ->configType . '_ ' . $ scopeType );
203
+
190
204
if ($ cachedData === false ) {
191
205
$ data = $ this ->readData ();
192
206
$ this ->cacheData ($ data );
193
207
} else {
194
208
$ data = [$ scopeType => $ this ->serializer ->unserialize ($ cachedData )];
195
209
}
210
+
196
211
return $ data ;
197
212
}
198
213
@@ -206,6 +221,7 @@ private function loadDefaultScopeData($scopeType)
206
221
private function loadScopeData ($ scopeType , $ scopeId )
207
222
{
208
223
$ cachedData = $ this ->cache ->load ($ this ->configType . '_ ' . $ scopeType . '_ ' . $ scopeId );
224
+
209
225
if ($ cachedData === false ) {
210
226
if ($ this ->availableDataScopes === null ) {
211
227
$ cachedScopeData = $ this ->cache ->load ($ this ->configType . '_scopes ' );
@@ -221,6 +237,7 @@ private function loadScopeData($scopeType, $scopeId)
221
237
} else {
222
238
$ data = [$ scopeType => [$ scopeId => $ this ->serializer ->unserialize ($ cachedData )]];
223
239
}
240
+
224
241
return $ data ;
225
242
}
226
243
@@ -244,7 +261,7 @@ private function cacheData(array $data)
244
261
[self ::CACHE_TAG ]
245
262
);
246
263
$ scopes = [];
247
- foreach ([' websites ' , ' stores ' ] as $ curScopeType ) {
264
+ foreach ([StoreScope:: SCOPE_WEBSITES , StoreScope:: SCOPE_STORES ] as $ curScopeType ) {
248
265
foreach ($ data [$ curScopeType ] ?? [] as $ curScopeId => $ curScopeData ) {
249
266
$ scopes [$ curScopeType ][$ curScopeId ] = 1 ;
250
267
$ this ->cache ->save (
@@ -256,7 +273,7 @@ private function cacheData(array $data)
256
273
}
257
274
$ this ->cache ->save (
258
275
$ this ->serializer ->serialize ($ scopes ),
259
- $ this ->configType . " _scopes " ,
276
+ $ this ->configType . ' _scopes ' ,
260
277
[self ::CACHE_TAG ]
261
278
);
262
279
}
@@ -279,6 +296,7 @@ private function getDataByPathParts($data, $pathParts)
279
296
return null ;
280
297
}
281
298
}
299
+
282
300
return $ data ;
283
301
}
284
302
0 commit comments