require a (de)normalizer inside the (de)normalizable interfaces instead of a serializer

This commit is contained in:
Lukas Kahwe Smith 2011-11-08 21:55:09 +01:00 committed by lsmith77
parent c3d61232c9
commit 351eaa8506
4 changed files with 12 additions and 14 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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'];

View File

@ -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;