1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Chubbyphp\Deserialization; |
6
|
|
|
|
7
|
|
|
final class DeserializerRuntimeException extends \RuntimeException |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @param string $path |
11
|
|
|
* @param string $givenType |
12
|
|
|
* @param string $wishedType |
13
|
|
|
* |
14
|
|
|
* @return self |
15
|
|
|
*/ |
16
|
1 |
|
public static function createInvalidDataType(string $path, string $givenType, string $wishedType): self |
17
|
|
|
{ |
18
|
1 |
|
return new self( |
19
|
1 |
|
sprintf('There is an invalid data type "%s", needed "%s" at path: "%s"', $givenType, $wishedType, $path) |
20
|
|
|
); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param string $contentType |
25
|
|
|
* |
26
|
|
|
* @return self |
27
|
|
|
*/ |
28
|
1 |
|
public static function createNotParsable(string $contentType): self |
29
|
|
|
{ |
30
|
1 |
|
return new self(sprintf('Data is not parsable with content-type: "%s"', $contentType)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param array $paths |
35
|
|
|
* |
36
|
|
|
* @return self |
37
|
|
|
*/ |
38
|
1 |
|
public static function createNotAllowedAdditionalFields(array $paths): self |
39
|
|
|
{ |
40
|
1 |
|
return new self(sprintf('There are additional field(s) at paths: "%s"', implode('", "', $paths))); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $path |
45
|
|
|
* @param array $supportedTypes |
46
|
|
|
* |
47
|
|
|
* @return self |
48
|
|
|
*/ |
49
|
1 |
|
public static function createMissingObjectType(string $path, array $supportedTypes): self |
50
|
|
|
{ |
51
|
1 |
|
return new self(sprintf( |
52
|
1 |
|
'Missing object type, supported are "%s" at path: "%s"', |
53
|
1 |
|
implode('", "', $supportedTypes), |
54
|
1 |
|
$path |
55
|
|
|
)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $path |
60
|
|
|
* @param string $type |
61
|
|
|
* @param array $supportedTypes |
62
|
|
|
* |
63
|
|
|
* @return self |
64
|
|
|
*/ |
65
|
1 |
|
public static function createInvalidObjectType(string $path, string $type, array $supportedTypes): self |
66
|
|
|
{ |
67
|
1 |
|
return new self(sprintf( |
68
|
1 |
|
'Unsupported object type "%s", supported are "%s" at path: "%s"', |
69
|
1 |
|
$type, |
70
|
1 |
|
implode('", "', $supportedTypes), |
71
|
1 |
|
$path |
72
|
|
|
)); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|