8000 refactored the EncoderInterface · symfony/symfony@58bd0f5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 58bd0f5

Browse files
committed
refactored the EncoderInterface
1 parent b0daf35 commit 58bd0f5

File tree

7 files changed

+68
-74
lines changed

7 files changed

+68
-74
lines changed

src/Symfony/Component/Serializer/Encoder/DecoderInterface.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414

1515
/**
16-
* Defines the interface of encoders that are able to decode their own format
16+
* Defines the interface of decoders
1717
*
1818
* @author Jordi Boggiano <j.boggiano@seld.be>
1919
*/
@@ -22,9 +22,17 @@ interface DecoderInterface
2222
/**
2323
* Decodes a string into PHP data
2424
*
25-
* @param string $data data to decode
26-
* @param string $format format to decode from
25+
* @param scalar $data data to decode
26+
* @param string $format format name
2727
* @return mixed
2828
*/
2929
function decode($data, $format);
30+
31+
/**
32+
* Checks whether the serializer can decode from given format
33+
*
34+
* @param string $format format name
35+
* @return Boolean
36+
*/
37+
function supportsDecoding($format);
3038
}

src/Symfony/Component/Serializer/Encoder/EncoderInterface.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Symfony\Component\Serializer\Encoder;
44

5-
65
/*
76
* This file is part of the Symfony framework.
87
*
@@ -20,11 +19,19 @@
2019
interface EncoderInterface
2120
{
2221
/**
23-
* Encodes data into a string
22+
* Encodes data into the given format
2423
*
2524
* @param mixed $data data to encode
26-
* @param string $format format to encode to
27-
* @return string
25+
* @param string $format format name
26+
* @return scalar
2827
*/
2928
function encode($data, $format);
29+
30+
/**
31+
* Checks whether the serializer can encode to given format
32+
*
33+
* @param string $format format name
34+
* @return Boolean
35+
*/
36+
function supportsEncoding($format);
3037
}

src/Symfony/Component/Serializer/Encoder/JsonEncoder.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,26 @@ public function decode($data, $format)
3434
{
3535
return json_decode($data, true);
3636
}
37+
38+
/**
39+
* Checks whether the serializer can encode to given format
40+
*
41+
* @param string $format format name
42+
* @return Boolean
43+
*/
44+
public function supportsEncoding($format)
45+
{
46+
return 'json' === $format;
47+
}
48+
49+
/**
50+
* Checks whether the serializer can decode from given format
51+
*
52+
* @param string $format format name
53+
* @return Boolean
54+
*/
55+
public function supportsDecoding($format)
56+
{
57+
return 'json' === $format;
58+
}
3759
}

src/Symfony/Component/Serializer/Encoder/XmlEncoder.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,28 @@ public function decode($data, $format)
7171
return $this->parseXml($xml);
7272
}
7373

74+
/**
75+
* Checks whether the serializer can encode to given format
76+
*
77+
* @param string $format format name
78+
* @return Boolean
79+
*/
80+
public function supportsEncoding($format)
81+
{
82+
return 'xml' === $format;
83+
}
84+
85+
/**
86+
* Checks whether the serializer can decode from given format
87+
*
88+
* @param string $format format name
89+
* @return Boolean
90+
*/
91+
public function supportsDecoding($format)
92+
{
93+
return 'xml' === $format;
94+
}
95+
7496
/**
7597
* Sets the root node name
7698
* @param string $name root node name

src/Symfony/Component/Serializer/EncoderInterface.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/Symfony/Component/Serializer/NormalizerInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Symfony\Component\Serializer;
44

5-
use Symfony\Component\Serializer\Encoder\EncoderInterface;
6-
75
/*
86
* This file is part of the Symfony framework.
97
*
@@ -14,7 +12,7 @@
1412
*/
1513

1614
/**
17-
* Defines the interface of the Normalizer
15+
* Defines the interface of Normalizers
1816
*
1917
* @author Jordi Boggiano <j.boggiano@seld.be>
2018
*/

src/Symfony/Component/Serializer/Serializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
3333
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
3434
*/
35-
class Serializer implements SerializerInterface, NormalizerInterface, EncoderInterface
35+
class Serializer implements SerializerInterface, NormalizerInterface, EncoderInterface, DecoderInterface
3636
{
3737
protected $normalizers = array();
3838
protected $encoders = array();

0 commit comments

Comments
 (0)
0