![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/app/code/Xtento/StockImport/Test/ |
<?php /** * Product: Xtento_StockImport * ID: u66QkJ5rBwmimhUzUElhIKqqWRvsbhC3WLqSMk5AjmQ= * Last Modified: 2019-02-05T17:10:52+00:00 * File: app/code/Xtento/StockImport/Test/SerializedToJsonDataConverter.php * Copyright: Copyright (c) XTENTO GmbH & Co. KG <[email protected]> / All rights reserved. */ namespace Xtento\StockImport\Test; use Magento\Framework\Serialize\Serializer\Serialize; use Magento\Framework\Serialize\Serializer\Json; /** * Serializer used to convert data to JSON * * This class is not a test. We had to place it here to avoid code compilation on pre-2.2 systems, where the implemented interface doesn't exist. */ class SerializedToJsonDataConverter implements \Magento\Framework\DB\DataConverter\DataConverterInterface { /** * @var Serialize */ private $serialize; /** * @var Json */ private $json; /** * Constructor * * @param Serialize $serialize * @param Json $json */ public function __construct( Serialize $serialize, Json $json ) { $this->serialize = $serialize; $this->json = $json; } /** * Convert from serialized to JSON format * * @param string $value * * @return string */ public function convert($value) { $isSerialized = $this->isSerialized($value); if (!$isSerialized) { return $value; } $unserialized = $this->serialize->unserialize($value); return $this->json->serialize($unserialized); } /** * Check if value is serialized string * * @param string $value * * @return boolean */ public function isSerialized($value) { if (is_array($value)) { return false; } return (boolean)preg_match('/^((s|i|d|b|a|O|C):|N;)/', $value); } }