require a (de)normalizer inside the (de)normalizable interfaces instead of a serializer
This commit is contained in:
parent
c3d61232c9
commit
351eaa8506
@ -2,8 +2,6 @@
|
||||
|
||||
namespace Symfony\Component\Serializer\Normalizer;
|
||||
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
@ -29,11 +27,11 @@ interface DenormalizableInterface
|
||||
* It is important to understand that the normalize() call should denormalize
|
||||
* recursively all child objects of the implementor.
|
||||
*
|
||||
* @param SerializerInterface $serializer The serializer is given so that you
|
||||
* @param DenormalizerInterface $denormalizer The denormalizer is given so that you
|
||||
* can use it to denormalize objects contained within this object.
|
||||
* @param array|scalar $data The data from which to re-create the object.
|
||||
* @param string|null $format The format is optionally given to be able to denormalize differently
|
||||
* based on different input formats.
|
||||
*/
|
||||
function denormalize(SerializerInterface $serializer, $data, $format = null);
|
||||
function denormalize(DenormalizerInterface $denormalizer, $data, $format = null);
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
namespace Symfony\Component\Serializer\Normalizer;
|
||||
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
@ -29,11 +27,11 @@ interface NormalizableInterface
|
||||
* It is important to understand that the normalize() call should normalize
|
||||
* recursively all child objects of the implementor.
|
||||
*
|
||||
* @param SerializerInterface $serializer The serializer is given so that you
|
||||
* @param NormalizerInterface $normalizer The normalizer is given so that you
|
||||
* can use it to normalize objects contained within this object.
|
||||
* @param string|null $format The format is optionally given to be able to normalize differently
|
||||
* based on different output formats.
|
||||
* @return array|scalar
|
||||
*/
|
||||
function normalize(SerializerInterface $serializer, $format = null);
|
||||
function normalize(NormalizerInterface $normalizer, $format = null);
|
||||
}
|
||||
|
@ -3,7 +3,8 @@
|
||||
namespace Symfony\Tests\Component\Serializer\Fixtures;
|
||||
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||
|
||||
class Dummy implements NormalizableInterface
|
||||
{
|
||||
@ -12,7 +13,7 @@ class Dummy implements NormalizableInterface
|
||||
public $baz;
|
||||
public $qux;
|
||||
|
||||
public function normalize(SerializerInterface $serializer, $format = null)
|
||||
public function normalize(NormalizerInterface $normalizer, $format = null)
|
||||
{
|
||||
return array(
|
||||
'foo' => $this->foo,
|
||||
@ -22,7 +23,7 @@ class Dummy implements NormalizableInterface
|
||||
);
|
||||
}
|
||||
|
||||
public function denormalize(SerializerInterface $serializer, $data, $format = null)
|
||||
public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null)
|
||||
{
|
||||
$this->foo = $data['foo'];
|
||||
$this->bar = $data['bar'];
|
||||
|
@ -3,19 +3,20 @@
|
||||
namespace Symfony\Tests\Component\Serializer\Fixtures;
|
||||
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||
|
||||
class ScalarDummy implements NormalizableInterface
|
||||
{
|
||||
public $foo;
|
||||
public $xmlFoo;
|
||||
|
||||
public function normalize(SerializerInterface $serializer, $format = null)
|
||||
public function normalize(NormalizerInterface $normalizer, $format = null)
|
||||
{
|
||||
return $format === 'xml' ? $this->xmlFoo : $this->foo;
|
||||
}
|
||||
|
||||
public function denormalize(SerializerInterface $serializer, $data, $format = null)
|
||||
public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null)
|
||||
{
|
||||
if ($format === 'xml') {
|
||||
$this->xmlFoo = $data;
|
||||
|
Reference in New Issue
Block a user