added a DecodeInterface (and SerializerAwareInterface) to make it easier to identify if an Encoder also supports decoding

This commit is contained in:
Lukas Kahwe Smith 2011-04-17 17:00:42 +02:00
parent c6818d8bf7
commit 874c4b6e07
6 changed files with 75 additions and 30 deletions

View File

@ -3,6 +3,7 @@
namespace Symfony\Component\Serializer\Encoder;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Serializer\SerializerAwareInterface;
/*
* This file is part of the Symfony framework.
@ -18,7 +19,7 @@ use Symfony\Component\Serializer\SerializerInterface;
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
abstract class AbstractEncoder implements EncoderInterface
abstract class AbstractEncoder implements SerializerAwareInterface, EncoderInterface
{
protected $serializer;
@ -37,4 +38,4 @@ abstract class AbstractEncoder implements EncoderInterface
{
return $this->serializer;
}
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Symfony\Component\Serializer\Encoder;
use Symfony\Component\Serializer\SerializerInterface;
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* Defines the interface of encoders
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
interface DecoderInterface
{
/**
* Decodes a string into PHP data
*
* @param string $data data to decode
* @param string $format format to decode from
* @return mixed
* @api
*/
function decode($data, $format);
}

View File

@ -29,30 +29,4 @@ interface EncoderInterface
* @api
*/
function encode($data, $format);
/**
* Decodes a string into PHP data
*
* @param string $data data to decode
* @param string $format format to decode from
* @return mixed
* @api
*/
function decode($data, $format);
/**
* Sets the owning Serializer object
*
* @param SerializerInterface $serializer
* @api
*/
function setSerializer(SerializerInterface $serializer);
/**
* Gets the owning Serializer object
*
* @return SerializerInterface
* @api
*/
function getSerializer();
}

View File

@ -18,7 +18,7 @@ use Symfony\Component\Serializer\SerializerInterface;
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class JsonEncoder extends AbstractEncoder
class JsonEncoder extends AbstractEncoder implements DecoderInterface
{
/**
* {@inheritdoc}

View File

@ -20,7 +20,7 @@ use Symfony\Component\Serializer\SerializerInterface;
* @author John Wards <jwards@whiteoctober.co.uk>
* @author Fabian Vogler <fabian@equivalence.ch>
*/
class XmlEncoder extends AbstractEncoder
class XmlEncoder extends AbstractEncoder implements DecoderInterface
{
private $dom;
private $format;

View File

@ -0,0 +1,38 @@
<?php
namespace Symfony\Component\Serializer;
use Symfony\Component\Serializer\SerializerInterface;
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* Defines the interface of encoders
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
interface SerializerAwareInterface
{
/**
* Sets the owning Serializer object
*
* @param SerializerInterface $serializer
* @api
*/
function setSerializer(SerializerInterface $serializer);
/**
* Gets the owning Serializer object
*
* @return SerializerInterface
* @api
*/
function getSerializer();
}