Skip to content

Commit

Permalink
refactored the EncoderInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Dec 11, 2011
1 parent a4303d8 commit 8ad2447
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 74 deletions.
14 changes: 11 additions & 3 deletions Encoder/DecoderInterface.php
Expand Up @@ -13,7 +13,7 @@
*/

/**
* Defines the interface of encoders that are able to decode their own format
* Defines the interface of decoders
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
Expand All @@ -22,9 +22,17 @@ interface DecoderInterface
/**
* Decodes a string into PHP data
*
* @param string $data data to decode
* @param string $format format to decode from
* @param scalar $data data to decode
* @param string $format format name
* @return mixed
*/
function decode($data, $format);

/**
* Checks whether the serializer can decode from given format
*
* @param string $format format name
* @return Boolean
*/
function supportsDecoding($format);
}
15 changes: 11 additions & 4 deletions Encoder/EncoderInterface.php
Expand Up @@ -2,7 +2,6 @@

namespace Symfony\Component\Serializer\Encoder;


/*
* This file is part of the Symfony framework.
*
Expand All @@ -20,11 +19,19 @@
interface EncoderInterface
{
/**
* Encodes data into a string
* Encodes data into the given format
*
* @param mixed $data data to encode
* @param string $format format to encode to
* @return string
* @param string $format format name
* @return scalar
*/
function encode($data, $format);

/**
* Checks whether the serializer can encode to given format
*
* @param string $format format name
* @return Boolean
*/
function supportsEncoding($format);
}
22 changes: 22 additions & 0 deletions Encoder/JsonEncoder.php
Expand Up @@ -34,4 +34,26 @@ public function decode($data, $format)
{
return json_decode($data, true);
}

/**
* Checks whether the serializer can encode to given format
*
* @param string $format format name
* @return Boolean
*/
public function supportsEncoding($format)
{
return 'json' === $format;
}

/**
* Checks whether the serializer can decode from given format
*
* @param string $format format name
* @return Boolean
*/
public function supportsDecoding($format)
{
return 'json' === $format;
}
}
22 changes: 22 additions & 0 deletions Encoder/XmlEncoder.php
Expand Up @@ -71,6 +71,28 @@ public function decode($data, $format)
return $this->parseXml($xml);
}

/**
* Checks whether the serializer can encode to given format
*
* @param string $format format name
* @return Boolean
*/
public function supportsEncoding($format)
{
return 'xml' === $format;
}

/**
* Checks whether the serializer can decode from given format
*
* @param string $format format name
* @return Boolean
*/
public function supportsDecoding($format)
{
return 'xml' === $format;
}

/**
* Sets the root node name
* @param string $name root node name
Expand Down
63 changes: 0 additions & 63 deletions EncoderInterface.php

This file was deleted.

4 changes: 1 addition & 3 deletions NormalizerInterface.php
Expand Up @@ -2,8 +2,6 @@

namespace Symfony\Component\Serializer;

use Symfony\Component\Serializer\Encoder\EncoderInterface;

/*
* This file is part of the Symfony framework.
*
Expand All @@ -14,7 +12,7 @@
*/

/**
* Defines the interface of the Normalizer
* Defines the interface of Normalizers
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
Expand Down
2 changes: 1 addition & 1 deletion Serializer.php
Expand Up @@ -32,7 +32,7 @@
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
*/
class Serializer implements SerializerInterface, NormalizerInterface, EncoderInterface
class Serializer implements SerializerInterface, NormalizerInterface, EncoderInterface, DecoderInterface
{
protected $normalizers = array();
protected $encoders = array();
Expand Down

0 comments on commit 8ad2447

Please sign in to comment.