1 | <?php |
||
25 | final class ObjectNormalizer extends Normalizer |
||
26 | { |
||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | 6 | public function normalize($object, $format = null, array $context = array()) |
|
31 | { |
||
32 | 6 | if ($object instanceof Activity) { |
|
33 | $activityData = array( |
||
34 | 6 | 'objectType' => 'Activity', |
|
35 | 6 | 'id' => $object->getId(), |
|
36 | ); |
||
37 | |||
38 | 6 | if (null !== $definition = $object->getDefinition()) { |
|
39 | 2 | $activityData['definition'] = $this->normalizeAttribute($definition, $format, $context); |
|
40 | } |
||
41 | |||
42 | 6 | return $activityData; |
|
43 | } |
||
44 | |||
45 | if ($object instanceof StatementReference) { |
||
46 | return array( |
||
47 | 'objectType' => 'StatementRef', |
||
48 | 'id' => $object->getStatementId(), |
||
49 | ); |
||
50 | } |
||
51 | |||
52 | if ($object instanceof SubStatement) { |
||
53 | $subStatement = new Statement($object->getId(), $object->getActor(), $object->getVerb(), $object->getObject(), $object->getResult()); |
||
54 | $subStatementData = $this->normalizeAttribute($subStatement, $format, $context); |
||
55 | $subStatementData['objectType'] = 'SubStatement'; |
||
56 | |||
57 | return $subStatementData; |
||
58 | } |
||
59 | |||
60 | return null; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | 48 | public function supportsNormalization($data, $format = null) |
|
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | 7 | public function denormalize($data, $class, $format = null, array $context = array()) |
|
75 | { |
||
76 | 7 | if (!isset($data['objectType']) || 'Activity' === $data['objectType']) { |
|
77 | 7 | return $this->denormalizeActivity($data, $format, $context); |
|
78 | } |
||
79 | |||
80 | if (isset($data['objectType']) && 'SubStatement' === $data['objectType']) { |
||
81 | return $this->denormalizeSubStatement($data, $format, $context); |
||
82 | } |
||
83 | |||
84 | if (isset($data['objectType']) && 'StatementRef' === $data['objectType']) { |
||
85 | return new StatementReference($data['id']); |
||
86 | } |
||
87 | |||
88 | return null; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | 49 | public function supportsDenormalization($data, $type, $format = null) |
|
98 | |||
99 | 7 | private function denormalizeActivity(array $data, $format = null, array $context = array()) |
|
109 | |||
110 | private function denormalizeSubStatement(array $data, $format = null, array $context = array()) |
||
111 | { |
||
127 | } |
||
128 |