5
5
*/
6
6
namespace Magento \Config \Model \Config \Backend ;
7
7
8
+ use Magento \Framework \Unserialize \SecureUnserializer ;
9
+ use Magento \Framework \App \ObjectManager ;
10
+
8
11
class Serialized extends \Magento \Framework \App \Config \Value
9
12
{
13
+ /**
14
+ * @var SecureUnserializer
15
+ */
16
+ private $ unserializer ;
17
+
18
+ /**
19
+ * Serialized constructor
20
+ *
21
+ * @param \Magento\Framework\Model\Context $context
22
+ * @param \Magento\Framework\Registry $registry
23
+ * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
24
+ * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
25
+ * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
26
+ * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
27
+ * @param array $data
28
+ * @param SecureUnserializer|null $unserializer
29
+ */
30
+ public function __construct (
31
+ \Magento \Framework \Model \Context $ context ,
32
+ \Magento \Framework \Registry $ registry ,
33
+ \Magento \Framework \App \Config \ScopeConfigInterface $ config ,
34
+ \Magento \Framework \App \Cache \TypeListInterface $ cacheTypeList ,
35
+ \Magento \Framework \Model \ResourceModel \AbstractResource $ resource = null ,
36
+ \Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
37
+ array $ data = [],
38
+ SecureUnserializer $ unserializer = null
39
+ ) {
40
+ parent ::__construct ($ context , $ registry , $ config , $ cacheTypeList , $ resource , $ resourceCollection , $ data );
41
+ $ this ->unserializer = $ unserializer ?: ObjectManager::getInstance ()->get (SecureUnserializer::class);
42
+ }
43
+
10
44
/**
11
45
* @return void
12
46
*/
13
47
protected function _afterLoad ()
14
48
{
15
- if (!is_array ($ this ->getValue ())) {
16
- $ value = $ this ->getValue ();
17
- $ this ->setValue (empty ($ value ) ? false : unserialize ($ value ));
49
+ $ value = $ this ->getValue ();
50
+ if (!is_array ($ value )) {
51
+ try {
52
+ $ this ->setValue (empty ($ value ) ? false : $ this ->unserializer ->unserialize ($ value ));
53
+ } catch (\Exception $ e ) {
54
+ $ this ->_logger ->critical ($ e );
55
+ $ this ->setValue (false );
56
+ }
18
57
}
19
58
}
20
59
@@ -23,9 +62,11 @@ protected function _afterLoad()
23
62
*/
24
63
public function beforeSave ()
25
64
{
26
- if (is_array ($ this ->getValue ())) {
27
- $ this ->setValue (serialize ($ this ->getValue ()));
65
+ $ value = $ this ->getValue ();
66
+ if (is_array ($ value )) {
67
+ $ this ->setValue (serialize ($ value ));
28
68
}
29
- return parent ::beforeSave ();
69
+ parent ::beforeSave ();
70
+ return $ this ;
30
71
}
31
72
}
0 commit comments