1 | <?php |
||
25 | final class ObjectNormalizer extends Normalizer |
||
26 | { |
||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | 45 | public function normalize($object, $format = null, array $context = array()) |
|
31 | { |
||
32 | 45 | if ($object instanceof Activity) { |
|
33 | $activityData = array( |
||
34 | 31 | 'objectType' => 'Activity', |
|
35 | 31 | 'id' => $object->getId(), |
|
36 | ); |
||
37 | |||
38 | 31 | if (null !== $definition = $object->getDefinition()) { |
|
39 | 4 | $activityData['definition'] = $this->normalizeAttribute($definition, $format, $context); |
|
40 | } |
||
41 | |||
42 | 31 | return $activityData; |
|
43 | } |
||
44 | |||
45 | 28 | if ($object instanceof StatementReference) { |
|
46 | return array( |
||
47 | 6 | 'objectType' => 'StatementRef', |
|
48 | 6 | 'id' => $object->getStatementId(), |
|
49 | ); |
||
50 | } |
||
51 | |||
52 | 23 | if ($object instanceof SubStatement) { |
|
53 | $data = array( |
||
54 | 23 | 'objectType' => 'SubStatement', |
|
55 | 23 | 'actor' => $this->normalizeAttribute($object->getActor(), $format, $context), |
|
56 | 23 | 'verb' => $this->normalizeAttribute($object->getVerb(), $format, $context), |
|
57 | 23 | 'object' => $this->normalizeAttribute($object->getObject(), $format, $context), |
|
58 | ); |
||
59 | |||
60 | 23 | if (null !== $result = $object->getResult()) { |
|
61 | 1 | $data['result'] = $this->normalizeAttribute($result, $format, $context); |
|
62 | } |
||
63 | |||
64 | 23 | if (null !== $statementContext = $object->getContext()) { |
|
65 | 1 | $data['context'] = $this->normalizeAttribute($statementContext, $format, $context); |
|
66 | } |
||
67 | |||
68 | 23 | return $data; |
|
69 | } |
||
70 | |||
71 | return null; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | 94 | public function supportsNormalization($data, $format = null) |
|
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | 46 | public function denormalize($data, $class, $format = null, array $context = array()) |
|
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | */ |
||
109 | 95 | public function supportsDenormalization($data, $type, $format = null) |
|
113 | |||
114 | 32 | private function denormalizeActivity(array $data, $format = null, array $context = array()) |
|
124 | |||
125 | 23 | private function denormalizeSubStatement(array $data, $format = null, array $context = array()) |
|
143 | } |
||
144 |