@@ 23-74 (lines=52) @@ | ||
20 | * |
|
21 | * @author Christian Flothmann <[email protected]> |
|
22 | */ |
|
23 | final class InteractionComponentNormalizer extends Normalizer implements DenormalizerInterface, NormalizerInterface |
|
24 | { |
|
25 | /** |
|
26 | * {@inheritdoc} |
|
27 | */ |
|
28 | public function normalize($object, $format = null, array $context = array()) |
|
29 | { |
|
30 | if (!$object instanceof InteractionComponent) { |
|
31 | return; |
|
32 | } |
|
33 | ||
34 | $data = array( |
|
35 | 'id' => $object->getId(), |
|
36 | ); |
|
37 | ||
38 | if (null !== $description = $object->getDescription()) { |
|
39 | $data['description'] = $this->normalizeAttribute($description, $format, $context); |
|
40 | } |
|
41 | ||
42 | return $data; |
|
43 | } |
|
44 | ||
45 | /** |
|
46 | * {@inheritdoc} |
|
47 | */ |
|
48 | public function supportsNormalization($data, $format = null) |
|
49 | { |
|
50 | return $data instanceof InteractionComponent; |
|
51 | } |
|
52 | ||
53 | /** |
|
54 | * {@inheritdoc} |
|
55 | */ |
|
56 | public function denormalize($data, $class, $format = null, array $context = array()) |
|
57 | { |
|
58 | $description = null; |
|
59 | ||
60 | if (isset($data['description'])) { |
|
61 | $description = $this->denormalizeData($data['description'], 'Xabbuh\XApi\Model\LanguageMap', $format, $context); |
|
62 | } |
|
63 | ||
64 | return new InteractionComponent($data['id'], $description); |
|
65 | } |
|
66 | ||
67 | /** |
|
68 | * {@inheritdoc} |
|
69 | */ |
|
70 | public function supportsDenormalization($data, $type, $format = null) |
|
71 | { |
|
72 | return 'Xabbuh\XApi\Model\Interaction\InteractionComponent' === $type; |
|
73 | } |
|
74 | } |
|
75 |
@@ 13-65 (lines=53) @@ | ||
10 | * |
|
11 | * @author Christian Flothmann <[email protected]> |
|
12 | */ |
|
13 | final class VerbNormalizer extends Normalizer |
|
14 | { |
|
15 | /** |
|
16 | * {@inheritdoc} |
|
17 | */ |
|
18 | public function normalize($object, $format = null, array $context = array()) |
|
19 | { |
|
20 | if (!$object instanceof Verb) { |
|
21 | return; |
|
22 | } |
|
23 | ||
24 | $data = array( |
|
25 | 'id' => $object->getId()->getValue(), |
|
26 | ); |
|
27 | ||
28 | if (null !== $display = $object->getDisplay()) { |
|
29 | $data['display'] = $this->normalizeAttribute($display, $format, $context); |
|
30 | } |
|
31 | ||
32 | return $data; |
|
33 | } |
|
34 | ||
35 | /** |
|
36 | * {@inheritdoc} |
|
37 | */ |
|
38 | public function supportsNormalization($data, $format = null) |
|
39 | { |
|
40 | return $data instanceof Verb; |
|
41 | } |
|
42 | ||
43 | /** |
|
44 | * {@inheritdoc} |
|
45 | */ |
|
46 | public function denormalize($data, $class, $format = null, array $context = array()) |
|
47 | { |
|
48 | $id = IRI::fromString($data['id']); |
|
49 | $display = null; |
|
50 | ||
51 | if (isset($data['display'])) { |
|
52 | $display = $this->denormalizeData($data['display'], 'Xabbuh\XApi\Model\LanguageMap', $format, $context); |
|
53 | } |
|
54 | ||
55 | return new Verb($id, $display); |
|
56 | } |
|
57 | ||
58 | /** |
|
59 | * {@inheritdoc} |
|
60 | */ |
|
61 | public function supportsDenormalization($data, $type, $format = null) |
|
62 | { |
|
63 | return 'Xabbuh\XApi\Model\Verb' === $type; |
|
64 | } |
|
65 | } |
|
66 |