Merge remote branch 'lsmith77/add_decoder_interface'
* lsmith77/add_decoder_interface: added a DecodeInterface (and SerializerAwareInterface) to make it easier to identify if an Encoder also supports decoding
This commit is contained in:
commit
f4aae27904
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
@ -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}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
Reference in New Issue
Block a user