diff --git a/app/etc/di.xml b/app/etc/di.xml index aa6f2eff91e0fdb907671b662910d5e9d94162cf..e430c15729d3d0cced20bf2b326d40f152b174e6 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\Serialize\SerializerInterface" type="Magento\Framework\Serialize\Json" /> + <preference for="Magento\Framework\Serialize\SerializerInterface" type="Magento\Framework\Serialize\Serializer\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/Serialize/README.md b/lib/internal/Magento/Framework/Serialize/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e636fc79818af6f749745cde1f2d76fea0473dcf --- /dev/null +++ b/lib/internal/Magento/Framework/Serialize/README.md @@ -0,0 +1,5 @@ +# Serialize + +**Serialize** libaray provides *SerializerInterface* and multiple implementations of serializer to support different kinds of needs of serializing/unserializing of data. Here are list of serializers in this library: + + * **Json** (default) - It can be used to serialize string, integer, float, boolean, or array data to json string; it unserializes json string to string, integer, float, boolean, or array. This is the recommended serializer. \ No newline at end of file diff --git a/lib/internal/Magento/Framework/Serialize/Json.php b/lib/internal/Magento/Framework/Serialize/Serializer/Json.php similarity index 79% rename from lib/internal/Magento/Framework/Serialize/Json.php rename to lib/internal/Magento/Framework/Serialize/Serializer/Json.php index 7b5f8a2006bbb236d523af87e196c6b87515bbcc..009fee5e3639f5ab5cd8cf9e1031f4a4129d98b4 100644 --- a/lib/internal/Magento/Framework/Serialize/Json.php +++ b/lib/internal/Magento/Framework/Serialize/Serializer/Json.php @@ -3,7 +3,9 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Serialize; +namespace Magento\Framework\Serialize\Serializer; + +use Magento\Framework\Serialize\SerializerInterface; class Json implements SerializerInterface { diff --git a/lib/internal/Magento/Framework/Serialize/SerializerInterface.php b/lib/internal/Magento/Framework/Serialize/SerializerInterface.php index 0f8fc7149b79d39cff44436810ae14a431ada2af..1dc70da80f39455690d34e750b07b9270c2d8d5e 100644 --- a/lib/internal/Magento/Framework/Serialize/SerializerInterface.php +++ b/lib/internal/Magento/Framework/Serialize/SerializerInterface.php @@ -10,17 +10,16 @@ interface SerializerInterface /** * Serialize data into string * - * @param array|string $data + * @param string|int|float|bool|array|null $data * @return string|bool */ public function serialize($data); /** - * Unserialize the given string into array + * Unserialize the given string * * @param string $string - * @param int $objectDecodeType - * @return array + * @return string|int|float|bool|array|null */ public function unserialize($string); } diff --git a/lib/internal/Magento/Framework/Serialize/Test/Unit/JsonTest.php b/lib/internal/Magento/Framework/Serialize/Test/Unit/Serializer/JsonTest.php similarity index 59% rename from lib/internal/Magento/Framework/Serialize/Test/Unit/JsonTest.php rename to lib/internal/Magento/Framework/Serialize/Test/Unit/Serializer/JsonTest.php index add2f60d44c6e9fc6393873419515539cf2c6143..38fa7d2a66f7f179a93bd11f45a35a996f937fe8 100644 --- a/lib/internal/Magento/Framework/Serialize/Test/Unit/JsonTest.php +++ b/lib/internal/Magento/Framework/Serialize/Test/Unit/Serializer/JsonTest.php @@ -3,15 +3,14 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Serialize\Test\Unit; +namespace Magento\Framework\Serialize\Test\Unit\Serializer; -use Magento\Framework\Serialize\SerializerInterface; -use Magento\Framework\Serialize\Json; +use Magento\Framework\Serialize\Serializer\Json; class JsonTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Framework\Serialize\Json + * @var \Magento\Framework\Serialize\Serializer\Json */ private $json; @@ -22,11 +21,10 @@ class JsonTest extends \PHPUnit_Framework_TestCase } /** - * @param null|bool|array|\stdClass $value - * @param int $objectDecodeType - * @dataProvider encodeDecodeDataProvider + * @param null|bool|array $value + * @dataProvider serializeUnserializeDataProvider */ - public function testEncodeDecode($value) + public function testSerializeUnserialize($value) { $this->assertEquals( $this->json->unserialize($this->json->serialize($value)), @@ -34,12 +32,11 @@ class JsonTest extends \PHPUnit_Framework_TestCase ); } - public function encodeDecodeDataProvider() + public function serializeUnserializeDataProvider() { - $object = new \stdClass(); - $object->a = 'b'; return [ [''], + ['string'], [null], [false], [['a' => 'b']],