Skip to content

Commit 9c5b75b

Browse files
author
graschik
committed
Refactor plugin
1 parent be016e0 commit 9c5b75b

File tree

1 file changed

+7
-34
lines changed

1 file changed

+7
-34
lines changed

Plugin/Magento/Widget/Block/Adminhtml/Widget/Options/DecodeComponentValues.php

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,23 @@
33

44
namespace Grasch\AdminUi\Plugin\Magento\Widget\Block\Adminhtml\Widget\Options;
55

6-
use Grasch\AdminUi\Model\Base64;
7-
use Magento\Framework\Exception\LocalizedException;
8-
use Magento\Framework\Serialize\SerializerInterface;
6+
use Grasch\AdminUi\Model\DecodeComponentValue;
97
use Magento\Widget\Block\Adminhtml\Widget\Options;
10-
use Psr\Log\LoggerInterface;
118

129
class DecodeComponentValues
1310
{
1411
/**
15-
* @var Base64
12+
* @var DecodeComponentValue
1613
*/
17-
private Base64 $base64;
14+
private DecodeComponentValue $decodeComponentValue;
1815

1916
/**
20-
* @var LoggerInterface
21-
*/
22-
private LoggerInterface $logger;
23-
24-
/**
25-
* @var SerializerInterface
26-
*/
27-
private SerializerInterface $serializer;
28-
29-
/**
30-
* @param Base64 $base64
31-
* @param LoggerInterface $logger
32-
* @param SerializerInterface $serializer
17+
* @param DecodeComponentValue $decodeComponentValue
3318
*/
3419
public function __construct(
35-
Base64 $base64,
36-
LoggerInterface $logger,
37-
SerializerInterface $serializer
20+
DecodeComponentValue $decodeComponentValue
3821
) {
39-
$this->base64 = $base64;
40-
$this->logger = $logger;
41-
$this->serializer = $serializer;
22+
$this->decodeComponentValue = $decodeComponentValue;
4223
}
4324

4425
/**
@@ -61,15 +42,7 @@ public function afterGetData(
6142
}
6243

6344
foreach ($result as &$value) {
64-
if (preg_match('/encodedComponentsData\|.*/', $value)) {
65-
$value = preg_replace('/encodedComponentsData\|/', '', $value);
66-
try {
67-
$value = $this->base64->decode($value);
68-
$value = $this->serializer->unserialize($value);
69-
} catch (LocalizedException $e) {
70-
$this->logger->error($e->getMessage());
71-
};
72-
}
45+
$value = $this->decodeComponentValue->execute($value);
7346
}
7447

7548
return $result;

0 commit comments

Comments
 (0)