Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b0daf35

Browse files
committed
split off an EncoderInterface and NormalizerInterface from SerializerInterface
1 parent fd12796 commit b0daf35

4 files changed

Lines changed: 105 additions & 61 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Symfony\Component\Serializer;
4+
5+
use Symfony\Component\Serializer\Encoder\EncoderInterface;
6+
7+
/*
8+
* This file is part of the Symfony framework.
9+
*
10+
* (c) Fabien Potencier <[email protected]>
11+
*
12+
* This source file is subject to the MIT license that is bundled
13+
* with this source code in the file LICENSE.
14+
*/
15+
16+
/**
17+
* Defines the interface of the Encoder
18+
*
19+
* @author Jordi Boggiano <[email protected]>
20+
*/
21+
interface EncoderInterface
22+
{
23+
/**
24+
* Encodes data into the given format
25+
*
26+
* @param mixed $data data to encode
27+
* @param string $format format name
28+
* @return array|scalar
29+
*/
30+
function encode($data, $format);
31+
32+
/**
33+
* Decodes a string from the given format back into PHP data
34+
*
35+
* @param string $data data to decode
36+
* @param string $format format name
37+
* @return mixed
38+
*/
39+
function decode($data, $format);
40+
41+
/**
42+
* Checks whether the serializer can encode to given format
43+
*
44+
* @param string $format format name
45+
* @return Boolean
46+
*/
47+
function supportsEncoding($format);
48+
49+
/**
50+
* Checks whether the serializer can decode from given format
51+
*
52+
* @param string $format format name
53+
* @return Boolean
54+
*/
55+
function supportsDecoding($format);
56+
57+
/**
58+
* Get the encoder for the given format
59+
*
60+
* @return EncoderInterface
61+
*/
62+
function getEncoder($format);
63+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Symfony\Component\Serializer;
4+
5+
use Symfony\Component\Serializer\Encoder\EncoderInterface;
6+
7+
/*
8+
* This file is part of the Symfony framework.
9+
*
10+
* (c) Fabien Potencier <[email protected]>
11+
*
12+
* This source file is subject to the MIT license that is bundled
13+
* with this source code in the file LICENSE.
14+
*/
15+
16+
/**
17+
* Defines the interface of the Normalizer
18+
*
19+
* @author Jordi Boggiano <[email protected]>
20+
*/
21+
interface NormalizerInterface
22+
{
23+
/**
24+
* Normalizes any data into a set of arrays/scalars
25+
*
26+
* @param mixed $data data to normalize
27+
* @param string $format format name, present to give the option to normalizers to act differently based on formats
28+
* @return array|scalar
29+
*/
30+
function normalize($data, $format = null);
31+
32+
/**
33+
* Denormalizes data into the given type.
34+
*
35+
* @param mixed $data
36+
* @param string $type
37+
* @param string $format
38+
* @return mixed
39+
*/
40+
function denormalize($data, $type, $format = null);
41+
}

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 <[email protected]>
3333
* @author Lukas Kahwe Smith <[email protected]>
3434
*/
35-
class Serializer implements SerializerInterface
35+
class Serializer implements SerializerInterface, NormalizerInterface, EncoderInterface
3636
{
3737
protected $normalizers = array();
3838
protected $encoders = array();

src/Symfony/Component/Serializer/SerializerInterface.php

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -38,43 +38,6 @@ function serialize($data, $format);
3838
*/
3939
function deserialize($data, $type, $format);
4040

41-
/**
42-
* Normalizes any data into a set of arrays/scalars
43-
*
44-
* @param mixed $data data to normalize
45-
* @param string $format format name, present to give the option to normalizers to act differently based on formats
46-
* @return array|scalar
47-
*/
48-
function normalize($data, $format = null);
49-
50-
/**
51-
* Denormalizes data into the given type.
52-
*
53-
* @param mixed $data
54-
* @param string $type
55-
* @param string $format
56-
* @return mixed
57-
*/
58-
function denormalize($data, $type, $format = null);
59-
60-
/**
61-
* Encodes data into the given format
62-
*
63-
* @param mixed $data data to encode
64-
* @param string $format format name
65-
* @return array|scalar
66-
*/
67-
function encode($data, $format);
68-
69-
/**
70-
* Decodes a string from the given format back into PHP data
71-
*
72-
* @param string $data data to decode
73-
* @param string $format format name
74-
* @return mixed
75-
*/
76-
function decode($data, $format);
77-
7841
/**
7942
* Checks whether the serializer can serialize to given format
8043
*
@@ -90,27 +53,4 @@ function supportsSerialization($format);
9053
* @return Boolean
9154
*/
9255
function supportsDeserialization($format);
93-
94-
/**
95-
* Checks whether the serializer can encode to given format
96-
*
97-
* @param string $format format name
98-
* @return Boolean
99-
*/
100-
function supportsEncoding($format);
101-
102-
/**
103-
* Checks whether the serializer can decode from given format
104-
*
105-
* @param string $format format name
106-
* @return Boolean
107-
*/
108-
function supportsDecoding($format);
109-
110-
/**
111-
* Get the encoder for the given format
112-
*
113-
* @return EncoderInterface
114-
*/
115-
function getEncoder($format);
11656
}

0 commit comments

Comments
 (0)