|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / dev2.destoffenstraat.com / app / code / Swissup / Recaptcha / Model / Config / Backend / |
Filename | /home/dev2.destoffenstraat.com/app/code/Swissup/Recaptcha/Model/Config/Backend/DesignException.php |
Size | 5.81 kb |
Permission | rw-rw-r-- |
Owner | root : root |
Create time | 17-Aug-2025 10:26 |
Last modified | 06-Jul-2023 16:45 |
Last accessed | 23-Aug-2025 02:07 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
namespace Swissup\Recaptcha\Model\Config\Backend;
class DesignException extends \Magento\Framework\App\Config\Value
{
private $mathRandom;
/**
* @param \Magento\Framework\Math\Random $mathRandom
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* @param array $data
*/
public function __construct(
\Magento\Framework\Math\Random $mathRandom,
\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 = []
) {
$this->mathRandom = $mathRandom;
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
}
/**
* Process data after load
*
* @return void
*/
protected function _afterLoad()
{
$value = $this->getValue();
$value = $this->makeArrayFieldValue($value);
$this->setValue($value);
}
/**
* Prepare data before save
*
* @return void
*/
public function beforeSave()
{
$value = $this->getValue();
$value = $this->makeStorableArrayFieldValue($value);
$this->setValue($value);
}
/**
* Check whether value is in form retrieved by _encodeArrayFieldValue()
*
* @param string|array $value
* @return bool
*/
protected function isEncodedArrayFieldValue($value)
{
if (!is_array($value)) {
return false;
}
unset($value['__empty']);
foreach ($value as $row) {
if (!is_array($row)
|| !array_key_exists('captcha_form', $row)
|| !array_key_exists('rtype', $row)
|| !array_key_exists('theme', $row)
|| !array_key_exists('size', $row)
|| !array_key_exists('badge', $row)
) {
return false;
}
}
return true;
}
/**
* Decode value from used in \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
*
* @param array $value
* @return array
*/
protected function decodeArrayFieldValue(array $value)
{
$result = [];
unset($value['__empty']);
foreach ($value as $row) {
if (!is_array($row)
|| !array_key_exists('captcha_form', $row)
|| !array_key_exists('rtype', $row)
|| !array_key_exists('theme', $row)
|| !array_key_exists('size', $row)
|| !array_key_exists('badge', $row)
) {
continue;
}
$captchaForm = $row['captcha_form'];
unset($row['captcha_form']);
$result[$captchaForm] = $row;
}
return $result;
}
/**
* Generate a storable representation of a value
*
* @param int|float|string|array $value
* @return string
*/
protected function serializeValue($value)
{
if (is_numeric($value)) {
$data = (float) $value;
return (string) $data;
} elseif (is_array($value)) {
$data = [];
foreach ($value as $captchaForm => $settings) {
$data[$captchaForm] = $settings;
}
return json_encode($data);
} else {
return '';
}
}
/**
* Make value ready for store
*
* @param string|array $value
* @return string
*/
public function makeStorableArrayFieldValue($value)
{
if ($this->isEncodedArrayFieldValue($value)) {
$value = $this->decodeArrayFieldValue($value);
}
$value = $this->serializeValue($value);
return $value;
}
/**
* Make value readable by \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
*
* @param string|array $value
* @return array
*/
public function makeArrayFieldValue($value)
{
$value = $this->unserializeValue($value);
if (!$this->isEncodedArrayFieldValue($value)) {
$value = $this->encodeArrayFieldValue($value);
}
return $value;
}
/**
* Create a value from a storable representation
*
* @param int|float|string $value
* @return array
*/
protected function unserializeValue($value)
{
$decodeAsArray = true;
if (is_string($value) && !empty($value)) {
return json_decode($value, $decodeAsArray);
} else {
return [];
}
}
/**
* Encode value to be used in \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
*
* @param array $value
* @return array
*/
protected function encodeArrayFieldValue(array $value)
{
$result = [];
foreach ($value as $captchaForm => $settings) {
$resultId = $this->mathRandom->getUniqueHash('_');
$result[$resultId] = ['captcha_form' => $captchaForm] + $settings;
}
return $result;
}
}
namespace Swissup\Recaptcha\Model\Config\Backend;
class DesignException extends \Magento\Framework\App\Config\Value
{
private $mathRandom;
/**
* @param \Magento\Framework\Math\Random $mathRandom
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* @param array $data
*/
public function __construct(
\Magento\Framework\Math\Random $mathRandom,
\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 = []
) {
$this->mathRandom = $mathRandom;
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
}
/**
* Process data after load
*
* @return void
*/
protected function _afterLoad()
{
$value = $this->getValue();
$value = $this->makeArrayFieldValue($value);
$this->setValue($value);
}
/**
* Prepare data before save
*
* @return void
*/
public function beforeSave()
{
$value = $this->getValue();
$value = $this->makeStorableArrayFieldValue($value);
$this->setValue($value);
}
/**
* Check whether value is in form retrieved by _encodeArrayFieldValue()
*
* @param string|array $value
* @return bool
*/
protected function isEncodedArrayFieldValue($value)
{
if (!is_array($value)) {
return false;
}
unset($value['__empty']);
foreach ($value as $row) {
if (!is_array($row)
|| !array_key_exists('captcha_form', $row)
|| !array_key_exists('rtype', $row)
|| !array_key_exists('theme', $row)
|| !array_key_exists('size', $row)
|| !array_key_exists('badge', $row)
) {
return false;
}
}
return true;
}
/**
* Decode value from used in \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
*
* @param array $value
* @return array
*/
protected function decodeArrayFieldValue(array $value)
{
$result = [];
unset($value['__empty']);
foreach ($value as $row) {
if (!is_array($row)
|| !array_key_exists('captcha_form', $row)
|| !array_key_exists('rtype', $row)
|| !array_key_exists('theme', $row)
|| !array_key_exists('size', $row)
|| !array_key_exists('badge', $row)
) {
continue;
}
$captchaForm = $row['captcha_form'];
unset($row['captcha_form']);
$result[$captchaForm] = $row;
}
return $result;
}
/**
* Generate a storable representation of a value
*
* @param int|float|string|array $value
* @return string
*/
protected function serializeValue($value)
{
if (is_numeric($value)) {
$data = (float) $value;
return (string) $data;
} elseif (is_array($value)) {
$data = [];
foreach ($value as $captchaForm => $settings) {
$data[$captchaForm] = $settings;
}
return json_encode($data);
} else {
return '';
}
}
/**
* Make value ready for store
*
* @param string|array $value
* @return string
*/
public function makeStorableArrayFieldValue($value)
{
if ($this->isEncodedArrayFieldValue($value)) {
$value = $this->decodeArrayFieldValue($value);
}
$value = $this->serializeValue($value);
return $value;
}
/**
* Make value readable by \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
*
* @param string|array $value
* @return array
*/
public function makeArrayFieldValue($value)
{
$value = $this->unserializeValue($value);
if (!$this->isEncodedArrayFieldValue($value)) {
$value = $this->encodeArrayFieldValue($value);
}
return $value;
}
/**
* Create a value from a storable representation
*
* @param int|float|string $value
* @return array
*/
protected function unserializeValue($value)
{
$decodeAsArray = true;
if (is_string($value) && !empty($value)) {
return json_decode($value, $decodeAsArray);
} else {
return [];
}
}
/**
* Encode value to be used in \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
*
* @param array $value
* @return array
*/
protected function encodeArrayFieldValue(array $value)
{
$result = [];
foreach ($value as $captchaForm => $settings) {
$resultId = $this->mathRandom->getUniqueHash('_');
$result[$resultId] = ['captcha_form' => $captchaForm] + $settings;
}
return $result;
}
}