diff --git a/app/etc/di.xml b/app/etc/di.xml index a44eff21dc86823b8fd132bf1e75adec54fdc767..aa6f2eff91e0fdb907671b662910d5e9d94162cf 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -154,7 +154,7 @@ <preference for="Magento\Framework\EntityManager\MapperInterface" type="Magento\Framework\EntityManager\CompositeMapper"/> <preference for="Magento\Framework\Console\CommandListInterface" type="Magento\Framework\Console\CommandList"/> <preference for="Magento\Framework\DataObject\IdentityGeneratorInterface" type="Magento\Framework\DataObject\IdentityService" /> - <preference for="Magento\Framework\Json\JsonInterface" type="Magento\Framework\Json\Json" /> + <preference for="Magento\Framework\Serialize\SerializerInterface" type="Magento\Framework\Serialize\Json" /> <type name="Magento\Framework\Model\ResourceModel\Db\TransactionManager" shared="false" /> <type name="Magento\Framework\Logger\Handler\Base"> <arguments> diff --git a/lib/internal/Magento/Framework/Json/Json.php b/lib/internal/Magento/Framework/Json/Json.php deleted file mode 100644 index c25f71cde4279779e4119b167e1cd47a9d240d41..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Json/Json.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php -/** - * Copyright © 2016 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Json; - -class Json implements JsonInterface -{ - /** - * {@inheritDoc} - */ - public function encode($data, $options = 0) - { - return json_encode($data, $options); - } - - /** - * {@inheritDoc} - */ - public function decode($string, $objectDecodeType = self::TYPE_ARRAY) - { - $result = json_decode($string, $objectDecodeType); - return $result; - } -} diff --git a/lib/internal/Magento/Framework/Json/JsonInterface.php b/lib/internal/Magento/Framework/Json/JsonInterface.php deleted file mode 100644 index 3d9df3d89e7ac3885e0d095916ddfca547332c6e..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Json/JsonInterface.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php -/** - * Copyright © 2016 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Json; - -interface JsonInterface -{ - /** - * Decode object as array - */ - const TYPE_ARRAY = 1; - - /** - * Decode object as object - */ - const TYPE_OBJECT = 0; - - /** - * Encode $data into the JSON format. Please see http://php.net/manual/en/function.json-encode.php for supported - * values for $option - * - * @param array|string $data - * @param int $options - * @return string|bool - */ - public function encode($data, $options = 0); - - /** - * Decode the given string which is encoded in the JSON format - * - * @param string $string - * @param int $objectDecodeType - * @return array|\stdClass - */ - public function decode($string, $objectDecodeType = self::TYPE_ARRAY); -} diff --git a/lib/internal/Magento/Framework/Serialize/Json.php b/lib/internal/Magento/Framework/Serialize/Json.php new file mode 100644 index 0000000000000000000000000000000000000000..7b5f8a2006bbb236d523af87e196c6b87515bbcc --- /dev/null +++ b/lib/internal/Magento/Framework/Serialize/Json.php @@ -0,0 +1,25 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Serialize; + +class Json implements SerializerInterface +{ + /** + * {@inheritDoc} + */ + public function serialize($data) + { + return json_encode($data); + } + + /** + * {@inheritDoc} + */ + public function unserialize($string) + { + return json_decode($string, true); + } +} diff --git a/lib/internal/Magento/Framework/Serialize/SerializerInterface.php b/lib/internal/Magento/Framework/Serialize/SerializerInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..0f8fc7149b79d39cff44436810ae14a431ada2af --- /dev/null +++ b/lib/internal/Magento/Framework/Serialize/SerializerInterface.php @@ -0,0 +1,26 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Serialize; + +interface SerializerInterface +{ + /** + * Serialize data into string + * + * @param array|string $data + * @return string|bool + */ + public function serialize($data); + + /** + * Unserialize the given string into array + * + * @param string $string + * @param int $objectDecodeType + * @return array + */ + public function unserialize($string); +} diff --git a/lib/internal/Magento/Framework/Json/Test/Unit/JsonTest.php b/lib/internal/Magento/Framework/Serialize/Test/Unit/JsonTest.php similarity index 59% rename from lib/internal/Magento/Framework/Json/Test/Unit/JsonTest.php rename to lib/internal/Magento/Framework/Serialize/Test/Unit/JsonTest.php index 7190e85c5dad5ee01e5b007fdc91f52a09e8bc96..add2f60d44c6e9fc6393873419515539cf2c6143 100644 --- a/lib/internal/Magento/Framework/Json/Test/Unit/JsonTest.php +++ b/lib/internal/Magento/Framework/Serialize/Test/Unit/JsonTest.php @@ -3,15 +3,15 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Json\Test\Unit; +namespace Magento\Framework\Serialize\Test\Unit; -use Magento\Framework\Json\JsonInterface; -use Magento\Framework\Json\Json; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Json; class JsonTest extends \PHPUnit_Framework_TestCase { /** - * @var Json + * @var \Magento\Framework\Serialize\Json */ private $json; @@ -26,10 +26,10 @@ class JsonTest extends \PHPUnit_Framework_TestCase * @param int $objectDecodeType * @dataProvider encodeDecodeDataProvider */ - public function testEncodeDecode($value, $objectDecodeType) + public function testEncodeDecode($value) { $this->assertEquals( - $this->json->decode($this->json->encode($value), $objectDecodeType), + $this->json->unserialize($this->json->serialize($value)), $value ); } @@ -39,11 +39,10 @@ class JsonTest extends \PHPUnit_Framework_TestCase $object = new \stdClass(); $object->a = 'b'; return [ - ['', JsonInterface::TYPE_ARRAY], - [null, JsonInterface::TYPE_ARRAY], - [false, JsonInterface::TYPE_ARRAY], - [['a' => 'b'], JsonInterface::TYPE_ARRAY], - [$object, JsonInterface::TYPE_OBJECT] + [''], + [null], + [false], + [['a' => 'b']], ]; } }