Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Serialized.php
Go to the documentation of this file.
1 <?php
7 
10 
15 class Serialized extends \Magento\Framework\App\Config\Value
16 {
20  private $serializer;
21 
34  public function __construct(
35  \Magento\Framework\Model\Context $context,
36  \Magento\Framework\Registry $registry,
38  \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
39  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
40  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
41  array $data = [],
42  Json $serializer = null
43  ) {
44  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
45  parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
46  }
47 
51  protected function _afterLoad()
52  {
53  $value = $this->getValue();
54  if (!is_array($value)) {
55  $this->setValue(empty($value) ? false : $this->serializer->unserialize($value));
56  }
57  }
58 
62  public function beforeSave()
63  {
64  if (is_array($this->getValue())) {
65  $this->setValue($this->serializer->serialize($this->getValue()));
66  }
67  parent::beforeSave();
68  return $this;
69  }
70 }
$config
Definition: fraud_order.php:17
$resource
Definition: bulk.php:12
$value
Definition: gender.phtml:16
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], Json $serializer=null)
Definition: Serialized.php:34