1 | <?php |
||
19 | final class ResultNormalizer extends Normalizer |
||
20 | { |
||
21 | /** |
||
22 | * {@inheritdoc} |
||
23 | */ |
||
24 | 1 | public function normalize($object, $format = null, array $context = array()) |
|
25 | { |
||
26 | 1 | if (!$object instanceof Result) { |
|
27 | return null; |
||
28 | } |
||
29 | |||
30 | $data = array( |
||
31 | 1 | 'score' => $this->normalizeAttribute($object->getScore(), 'Xabbuh\XApi\Model\Score', $context), |
|
32 | 1 | 'success' => $object->getSuccess(), |
|
33 | 1 | 'completion' => $object->getCompletion(), |
|
34 | ); |
||
35 | |||
36 | 1 | if (null !== $response = $object->getResponse()) { |
|
37 | 1 | $data['response'] = $response; |
|
38 | } |
||
39 | |||
40 | 1 | if (null !== $duration = $object->getDuration()) { |
|
41 | 1 | $data['duration'] = $duration; |
|
42 | } |
||
43 | |||
44 | 1 | return $data; |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | 9 | public function supportsNormalization($data, $format = null) |
|
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | 1 | public function denormalize($data, $class, $format = null, array $context = array()) |
|
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | 10 | public function supportsDenormalization($data, $type, $format = null) |
|
74 | } |
||
75 |