/
SerializerInterface.php
108 lines (94 loc) · 2.89 KB
/
SerializerInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Symfony\Component\Serializer;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.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 the Serializer
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
interface SerializerInterface
{
/**
* Serializes data in the appropriate format
*
* @param mixed $data any data
* @param string $format format name
* @return string
*/
function serialize($data, $format);
/**
* Normalizes any data into a set of arrays/scalars
*
* @param mixed $data data to normalize
* @param string $format format name, present to give the option to normalizers to act differently based on formats
* @return array|scalar
*/
function normalize($data, $format);
/**
* Normalizes an object into a set of arrays/scalars
*
* @param object $object object to normalize
* @param string $format format name, present to give the option to normalizers to act differently based on formats
* @param array $properties a list of properties to extract, if null all properties are returned
* @return array|scalar
*/
function normalizeObject($object, $format, $properties = null);
/**
* Denormalizes data back into an object of the given class
*
* @param mixed $data data to restore
* @param string $class the expected class to instantiate
* @param string $format format name, present to give the option to normalizers to act differently based on formats
* @return object
*/
function denormalizeObject($data, $class, $format = null);
/**
* Encodes data into the given format
*
* @param mixed $data data to encode
* @param string $format format name
* @return array|scalar
*/
function encode($data, $format);
/**
* Decodes a string from the given format back into PHP data
*
* @param string $data data to decode
* @param string $format format name
* @return mixed
*/
function decode($data, $format);
/**
* @param string $format format name
* @param EncoderInterface $encoder
*/
function addEncoder($format, EncoderInterface $encoder);
/**
* @param string $format format name
* @return EncoderInterface
*/
function getEncoders();
/**
* @return array[]EncoderInterface
*/
function getEncoder($format);
/**
* Checks whether the serializer has an encoder registered for the given format
*
* @param string $format format name
* @return Boolean
*/
function hasEncoder($format);
/**
* @param string $format format name
*/
function removeEncoder($format);
}