1 | <?php |
||
2 | |||
3 | namespace Bdf\Serializer; |
||
4 | |||
5 | /** |
||
6 | * SerializerInterface |
||
7 | */ |
||
8 | interface SerializerInterface |
||
9 | { |
||
10 | /** |
||
11 | * Serializes the given data to the specified output format. |
||
12 | * |
||
13 | * @param object|array|mixed $data |
||
14 | * @param string $format |
||
15 | * @param array $context |
||
16 | * |
||
17 | * @return string|array |
||
18 | */ |
||
19 | public function serialize($data, $format, array $context = []); |
||
20 | |||
21 | /** |
||
22 | * Deserializes the given data to the specified type. |
||
23 | * |
||
24 | * @param mixed $data |
||
25 | * @param class-string<T>|T $type The type of data. Can be the target object. |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
26 | * @param string $format |
||
27 | * @param array $context |
||
28 | * |
||
29 | * @return T|T[] |
||
30 | * |
||
31 | * @template T |
||
32 | */ |
||
33 | public function deserialize($data, $type, $format, array $context = []); |
||
34 | |||
35 | /** |
||
36 | * Serialize data to json |
||
37 | * |
||
38 | * @param mixed $data |
||
39 | * @param array $context |
||
40 | * |
||
41 | * @return string |
||
42 | */ |
||
43 | public function toJson($data, array $context = []); |
||
44 | |||
45 | /** |
||
46 | * Restores objects from json. |
||
47 | * |
||
48 | * @param string $json |
||
49 | * @param class-string<T>|T $type The type of data. Can be the target object. |
||
0 ignored issues
–
show
|
|||
50 | * @param array $context |
||
51 | * |
||
52 | * @return T|T[] this returns whatever the passed type is, typically an object or an array of objects |
||
53 | * |
||
54 | * @template T |
||
55 | */ |
||
56 | public function fromJson(string $json, $type, array $context = []); |
||
57 | |||
58 | /** |
||
59 | * Converts objects to an array structure. |
||
60 | * |
||
61 | * This is useful when the data needs to be passed on to other methods which expect array data. |
||
62 | * |
||
63 | * @param mixed $data anything that converts to an array, typically an object or an array of objects |
||
64 | * @param array $context |
||
65 | * |
||
66 | * @return array |
||
67 | */ |
||
68 | public function toArray($data, array $context = []); |
||
69 | |||
70 | /** |
||
71 | * Restores objects from an array structure. |
||
72 | * |
||
73 | * @param array $data |
||
74 | * @param class-string<T>|T $type The type of data. Can be the target object. |
||
0 ignored issues
–
show
|
|||
75 | * @param array $context |
||
76 | * |
||
77 | * @return T|T[] this returns whatever the passed type is, typically an object or an array of objects |
||
78 | * |
||
79 | * @template T |
||
80 | */ |
||
81 | public function fromArray(array $data, $type, array $context = []); |
||
82 | } |
||
83 |