12
12
use Magento \Framework \Cache \FrontendInterface ;
13
13
use Magento \Framework \App \ObjectManager ;
14
14
use Magento \Config \App \Config \Type \System \Reader ;
15
+ use Magento \Framework \Encryption \EncryptorInterface ;
15
16
use Magento \Store \Model \Config \Processor \Fallback ;
16
17
17
18
/**
@@ -101,6 +102,11 @@ class System implements ConfigTypeInterface
101
102
*/
102
103
private $ availableDataScopes = null ;
103
104
105
+ /**
106
+ * @var EncryptorInterface
107
+ */
108
+ private $ encryptor ;
109
+
104
110
/**
105
111
* @param ConfigSourceInterface $source
106
112
* @param PostProcessorInterface $postProcessor
@@ -110,6 +116,7 @@ class System implements ConfigTypeInterface
110
116
* @param int $cachingNestedLevel
111
117
* @param string $configType
112
118
* @param Reader $reader
119
+ * @param EncryptorInterface|null $encryptor
113
120
*/
114
121
public function __construct (
115
122
ConfigSourceInterface $ source ,
@@ -119,7 +126,8 @@ public function __construct(
119
126
PreProcessorInterface $ preProcessor ,
120
127
$ cachingNestedLevel = 1 ,
121
128
$ configType = self ::CONFIG_TYPE ,
122
- Reader $ reader = null
129
+ Reader $ reader = null ,
130
+ EncryptorInterface $ encryptor = null
123
131
) {
124
132
$ this ->source = $ source ;
125
133
$ this ->postProcessor = $ postProcessor ;
@@ -129,6 +137,8 @@ public function __construct(
129
137
$ this ->fallback = $ fallback ;
130
138
$ this ->configType = $ configType ;
131
139
$ this ->reader = $ reader ?: ObjectManager::getInstance ()->get (Reader::class);
140
+ $ this ->encryptor = $ encryptor ?: ObjectManager::getInstance ()
141
+ ->get (EncryptorInterface::class);
132
142
}
133
143
134
144
/**
@@ -193,7 +203,8 @@ private function loadAllData()
193
203
if ($ cachedData === false ) {
194
204
$ data = $ this ->reader ->read ();
195
205
} else {
196
- $ data = unserialize ($ cachedData );
206
+
207
+ $ data = unserialize ($ this ->encryptor ->decrypt ($ cachedData ));
197
208
}
198
209
199
210
return $ data ;
@@ -212,7 +223,11 @@ private function loadDefaultScopeData($scopeType)
212
223
$ data = $ this ->reader ->read ();
213
224
$ this ->cacheData ($ data );
214
225
} else {
215
- $ data = [$ scopeType => unserialize ($ cachedData )];
226
+ $ data = [
227
+ $ scopeType => unserialize (
228
+ $ this ->encryptor ->decrypt ($ cachedData )
229
+ )
230
+ ];
216
231
}
217
232
218
233
return $ data ;
@@ -232,7 +247,9 @@ private function loadScopeData($scopeType, $scopeId)
232
247
if ($ this ->availableDataScopes === null ) {
233
248
$ cachedScopeData = $ this ->cache ->load ($ this ->configType . '_scopes ' );
234
249
if ($ cachedScopeData !== false ) {
235
- $ this ->availableDataScopes = unserialize ($ cachedScopeData );
250
+ $ this ->availableDataScopes = unserialize (
251
+ $ this ->encryptor ->decrypt ($ cachedScopeData )
252
+ );
236
253
}
237
254
}
238
255
if (is_array ($ this ->availableDataScopes ) && !isset ($ this ->availableDataScopes [$ scopeType ][$ scopeId ])) {
@@ -241,7 +258,13 @@ private function loadScopeData($scopeType, $scopeId)
241
258
$ data = $ this ->reader ->read ();
242
259
$ this ->cacheData ($ data );
243
260
} else {
244
- $ data = [$ scopeType => [$ scopeId => unserialize ($ cachedData )]];
261
+ $ data = [
262
+ $ scopeType => [
263
+ $ scopeId => unserialize (
264
+ $ this ->encryptor ->decrypt ($ cachedData )
265
+ )
266
+ ]
267
+ ];
245
268
}
246
269
247
270
return $ data ;
@@ -257,12 +280,12 @@ private function loadScopeData($scopeType, $scopeId)
257
280
private function cacheData (array $ data )
258
281
{
259
282
$ this ->cache ->save (
260
- serialize ($ data ),
283
+ $ this -> encryptor -> encrypt ( serialize ($ data) ),
261
284
$ this ->configType ,
262
285
[self ::CACHE_TAG ]
263
286
);
264
287
$ this ->cache ->save (
265
- serialize ($ data ['default ' ]),
288
+ $ this -> encryptor -> encrypt ( serialize ($ data ['default ' ]) ),
266
289
$ this ->configType . '_default ' ,
267
290
[self ::CACHE_TAG ]
268
291
);
@@ -271,14 +294,14 @@ private function cacheData(array $data)
271
294
foreach ($ data [$ curScopeType ] as $ curScopeId => $ curScopeData ) {
272
295
$ scopes [$ curScopeType ][$ curScopeId ] = 1 ;
273
296
$ this ->cache ->save (
274
- serialize ($ curScopeData ),
297
+ $ this -> encryptor -> encrypt ( serialize ($ curScopeData) ),
275
298
$ this ->configType . '_ ' . $ curScopeType . '_ ' . $ curScopeId ,
276
299
[self ::CACHE_TAG ]
277
300
);
278
301
}
279
302
}
280
303
$ this ->cache ->save (
281
- serialize ($ scopes ),
304
+ $ this -> encryptor -> encrypt ( serialize ($ scopes) ),
282
305
$ this ->configType . "_scopes " ,
283
306
[self ::CACHE_TAG ]
284
307
);
0 commit comments