|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Smartbox\CoreBundle\Serializer; |
|
4
|
|
|
|
|
5
|
|
|
use JMS\Serializer\AbstractVisitor; |
|
6
|
|
|
use JMS\Serializer\Context; |
|
7
|
|
|
use JMS\Serializer\Exception\RuntimeException; |
|
8
|
|
|
use JMS\Serializer\GraphNavigator; |
|
9
|
|
|
use JMS\Serializer\Metadata\ClassMetadata; |
|
10
|
|
|
use JMS\Serializer\Metadata\PropertyMetadata; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* This is a really simple visitor that will effectively bypass JMS. |
|
14
|
|
|
* Useful for cases when JMS receives a plain text to deserialize. |
|
15
|
|
|
*/ |
|
16
|
|
|
class PlainTextDeserializationVisitor extends AbstractVisitor |
|
17
|
|
|
{ |
|
18
|
|
|
public function visitNull($data, array $type, Context $context) |
|
19
|
|
|
{ |
|
20
|
|
|
throw new RuntimeException('PlainTextDeserializationVisitor cannot visit Null types.'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function visitString($data, array $type, Context $context) |
|
24
|
|
|
{ |
|
25
|
|
|
return (string) $data; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function visitBoolean($data, array $type, Context $context) |
|
29
|
|
|
{ |
|
30
|
|
|
throw new RuntimeException('PlainTextDeserializationVisitor cannot visit Boolean types.'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function visitDouble($data, array $type, Context $context) |
|
34
|
|
|
{ |
|
35
|
|
|
throw new RuntimeException('PlainTextDeserializationVisitor cannot visit Double types.'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function visitInteger($data, array $type, Context $context) |
|
39
|
|
|
{ |
|
40
|
|
|
throw new RuntimeException('PlainTextDeserializationVisitor cannot visit Integer types.'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function visitArray($data, array $type, Context $context) |
|
44
|
|
|
{ |
|
45
|
|
|
throw new RuntimeException('PlainTextDeserializationVisitor cannot visit Array types.'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function startVisitingObject(ClassMetadata $metadata, $data, array $type, Context $context) |
|
49
|
|
|
{ |
|
50
|
|
|
// noop |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function visitProperty(PropertyMetadata $metadata, $data, Context $context) |
|
54
|
|
|
{ |
|
55
|
|
|
throw new RuntimeException('PlainTextDeserializationVisitor cannot visit properties.'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function endVisitingObject(ClassMetadata $metadata, $data, array $type, Context $context) |
|
59
|
|
|
{ |
|
60
|
|
|
// noop |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function setNavigator(GraphNavigator $navigator) |
|
64
|
|
|
{ |
|
65
|
|
|
// noop |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getNavigator() |
|
69
|
|
|
{ |
|
70
|
|
|
// noop |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function getResult() |
|
74
|
|
|
{ |
|
75
|
|
|
return null; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|