1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the xAPI package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xabbuh\XApi\Serializer\Normalizer; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
15
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
16
|
|
|
use Xabbuh\XApi\Model\Interaction\InteractionComponent; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Denormalizes xAPI statement activity {@link InteractionComponent interaction components}. |
20
|
|
|
* |
21
|
|
|
* @author Christian Flothmann <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
final class InteractionComponentNormalizer extends Normalizer implements DenormalizerInterface, NormalizerInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
8 |
|
public function normalize($object, $format = null, array $context = array()) |
29
|
|
|
{ |
30
|
8 |
|
if (!$object instanceof InteractionComponent) { |
31
|
|
|
return; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$data = array( |
35
|
8 |
|
'id' => $object->getId(), |
36
|
|
|
); |
37
|
|
|
|
38
|
8 |
|
if (null !== $description = $object->getDescription()) { |
39
|
1 |
|
$data['description'] = $this->normalizeAttribute($description, $format, $context); |
40
|
|
|
} |
41
|
|
|
|
42
|
8 |
|
return $data; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
121 |
|
public function supportsNormalization($data, $format = null) |
49
|
|
|
{ |
50
|
121 |
|
return $data instanceof InteractionComponent; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
8 |
|
public function denormalize($data, $class, $format = null, array $context = array()) |
57
|
|
|
{ |
58
|
8 |
|
$description = null; |
59
|
|
|
|
60
|
8 |
|
if (isset($data['description'])) { |
61
|
1 |
|
$description = $this->denormalizeData($data['description'], 'Xabbuh\XApi\Model\LanguageMap', $format, $context); |
62
|
|
|
} |
63
|
|
|
|
64
|
8 |
|
return new InteractionComponent($data['id'], $description); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
127 |
|
public function supportsDenormalization($data, $type, $format = null) |
71
|
|
|
{ |
72
|
127 |
|
return 'Xabbuh\XApi\Model\Interaction\InteractionComponent' === $type; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|