Skip to content

Remove decoder interface usage #10453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/code/Magento/Ui/Controller/Adminhtml/Bookmark/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,15 @@ class Save extends AbstractAction

/**
* @var DecoderInterface
* @deprecated
*/
protected $jsonDecoder;

/**
* @var \Magento\Framework\Serialize\Serializer\Json
*/
private $serializer;

/**
* @param Context $context
* @param UiComponentFactory $factory
Expand All @@ -64,6 +70,8 @@ class Save extends AbstractAction
* @param BookmarkInterfaceFactory $bookmarkFactory
* @param UserContextInterface $userContext
* @param DecoderInterface $jsonDecoder
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @throws \RuntimeException
*/
public function __construct(
Context $context,
Expand All @@ -72,20 +80,25 @@ public function __construct(
BookmarkManagementInterface $bookmarkManagement,
BookmarkInterfaceFactory $bookmarkFactory,
UserContextInterface $userContext,
DecoderInterface $jsonDecoder
DecoderInterface $jsonDecoder,
\Magento\Framework\Serialize\Serializer\Json $serializer = null
) {
parent::__construct($context, $factory);
$this->bookmarkRepository = $bookmarkRepository;
$this->bookmarkManagement = $bookmarkManagement;
$this->bookmarkFactory = $bookmarkFactory;
$this->userContext = $userContext;
$this->jsonDecoder = $jsonDecoder;
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
}

/**
* Action for AJAX request
*
* @return void
* @throws \InvalidArgumentException
* @throws \LogicException
*/
public function execute()
{
Expand All @@ -94,7 +107,7 @@ public function execute()
if (!$jsonData) {
throw new \InvalidArgumentException('Invalid parameter "data"');
}
$data = $this->jsonDecoder->decode($jsonData);
$data = $this->serializer->unserialize($jsonData);
$action = key($data);
switch ($action) {
case self::ACTIVE_IDENTIFIER:
Expand Down
15 changes: 13 additions & 2 deletions app/code/Magento/Ui/Model/Bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ class Bookmark extends AbstractExtensibleModel implements BookmarkInterface
{
/**
* @var DecoderInterface
* @deprecated
*/
protected $jsonDecoder;

/**
* @var \Magento\Framework\Serialize\Serializer\Json
*/
private $serializer;

/**
* @param Context $context
* @param Registry $registry
Expand All @@ -35,6 +41,8 @@ class Bookmark extends AbstractExtensibleModel implements BookmarkInterface
* @param Collection $resourceCollection
* @param DecoderInterface $jsonDecoder
* @param array $data
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @throws \RuntimeException
*/
public function __construct(
Context $context,
Expand All @@ -44,9 +52,12 @@ public function __construct(
ResourceBookmark $resource,
Collection $resourceCollection,
DecoderInterface $jsonDecoder,
array $data = []
array $data = [],
\Magento\Framework\Serialize\Serializer\Json $serializer = null
) {
$this->jsonDecoder = $jsonDecoder;
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
parent::__construct(
$context,
$registry,
Expand Down Expand Up @@ -127,7 +138,7 @@ public function getConfig()
{
$config = $this->getData(self::CONFIG);
if ($config) {
return $this->jsonDecoder->decode($config);
return $this->serializer->unserialize($config);
}
return [];
}
Expand Down