Skip to content

Commit

Permalink
MAGETWO-59444: Create serializer interface and json class in framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Joan He committed Oct 17, 2016
1 parent 3977f57 commit 363f1ca
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 75 deletions.
2 changes: 1 addition & 1 deletion app/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
25 changes: 0 additions & 25 deletions lib/internal/Magento/Framework/Json/Json.php

This file was deleted.

38 changes: 0 additions & 38 deletions lib/internal/Magento/Framework/Json/JsonInterface.php

This file was deleted.

25 changes: 25 additions & 0 deletions lib/internal/Magento/Framework/Serialize/Json.php
Original file line number Diff line number Diff line change
@@ -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);
}
}
26 changes: 26 additions & 0 deletions lib/internal/Magento/Framework/Serialize/SerializerInterface.php
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -26,10 +26,10 @@ protected function setUp()
* @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
);
}
Expand All @@ -39,11 +39,10 @@ public function encodeDecodeDataProvider()
$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']],
];
}
}

0 comments on commit 363f1ca

Please # to comment.