Repository navigation
Expand file tree
/
Copy pathSerializer.php
More file actions
53 lines (46 loc) · 2.28 KB
/
Copy pathSerializer.php
File metadata and controls
53 lines (46 loc) · 2.28 KB
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
<?php
declare(strict_types=1);
namespace TinyBlocks\Mapper;
use TinyBlocks\Mapper\Exceptions\UnknownSubtype;
/**
* Serializes objects to portable arrays and JSON.
*/
interface Serializer
{
/**
* Returns the given object as a JSON string.
*
* @param object $source The instance to serialize.
* @param Configuration|null $configuration Per-call output options. Defaults to {@see Configuration::default()}.
* @return string The JSON representation.
* @throws UnknownSubtype If the concrete class matches no subtype case.
*/
public function toJson(object $source, ?Configuration $configuration = null): string;
/**
* Returns the given object as an array.
*
* @param object $source The instance to serialize.
* @param Configuration|null $configuration Per-call output options. Defaults to {@see Configuration::default()}.
* @return array<int|string, mixed> The array representation, with nested objects and collections resolved.
* @throws UnknownSubtype If the concrete class matches no subtype case.
*/
public function toArray(object $source, ?Configuration $configuration = null): array;
/**
* Returns the given object as a JSON string, or null when the source is null.
*
* @param object|null $source The instance to serialize, or null.
* @param Configuration|null $configuration Per-call output options. Defaults to {@see Configuration::default()}.
* @return string|null The JSON representation, or null when the source is null.
* @throws UnknownSubtype If a non-null source's concrete class matches no subtype case.
*/
public function toJsonOrNull(?object $source, ?Configuration $configuration = null): ?string;
/**
* Returns the given object as an array, or null when the source is null.
*
* @param object|null $source The instance to serialize, or null.
* @param Configuration|null $configuration Per-call output options. Defaults to {@see Configuration::default()}.
* @return array<int|string, mixed>|null The array representation, or null when the source is null.
* @throws UnknownSubtype If a non-null source's concrete class matches no subtype case.
*/
public function toArrayOrNull(?object $source, ?Configuration $configuration = null): ?array;
}