Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Encrypted.php
Go to the documentation of this file.
1 <?php
10 
15 class Encrypted extends \Magento\Framework\App\Config\Value implements
16  \Magento\Framework\App\Config\Data\ProcessorInterface
17 {
21  protected $_encryptor;
22 
33  public function __construct(
34  \Magento\Framework\Model\Context $context,
35  \Magento\Framework\Registry $registry,
37  \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
38  \Magento\Framework\Encryption\EncryptorInterface $encryptor,
39  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
40  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
41  array $data = []
42  ) {
43  $this->_encryptor = $encryptor;
44  parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
45  }
46 
52  public function __sleep()
53  {
55  return array_diff($properties, ['_encryptor']);
56  }
57 
63  public function __wakeup()
64  {
66  $this->_encryptor = \Magento\Framework\App\ObjectManager::getInstance()->get(
67  \Magento\Framework\Encryption\EncryptorInterface::class
68  );
69  }
70 
76  protected function _afterLoad()
77  {
78  $value = (string)$this->getValue();
79  if (!empty($value) && ($decrypted = $this->_encryptor->decrypt($value))) {
80  $this->setValue($decrypted);
81  }
82  }
83 
89  public function beforeSave()
90  {
91  $this->_dataSaveAllowed = false;
92  $value = (string)$this->getValue();
93  // don't save value, if an obscured value was received. This indicates that data was not changed.
94  if (!preg_match('/^\*+$/', $value) && !empty($value)) {
95  $this->_dataSaveAllowed = true;
96  $encrypted = $this->_encryptor->encrypt($value);
97  $this->setValue($encrypted);
98  } elseif (empty($value)) {
99  $this->_dataSaveAllowed = true;
100  }
101  }
102 
109  public function processValue($value)
110  {
111  return $this->_encryptor->decrypt($value);
112  }
113 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$config
Definition: fraud_order.php:17
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Encrypted.php:33
$resource
Definition: bulk.php:12
$value
Definition: gender.phtml:16
$properties
Definition: categories.php:26