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 Xabbuh\XApi\Model\Result; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Normalizes and denormalizes xAPI statement results. |
18
|
|
|
* |
19
|
|
|
* @author Christian Flothmann <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
final class ResultNormalizer extends Normalizer |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
11 |
|
public function normalize($object, $format = null, array $context = array()) |
27
|
|
|
{ |
28
|
11 |
|
if (!$object instanceof Result) { |
29
|
|
|
return null; |
30
|
|
|
} |
31
|
|
|
|
32
|
11 |
|
$data = array(); |
33
|
|
|
|
34
|
11 |
|
if (null !== $object->getScore()) { |
35
|
7 |
|
$data['score'] = $this->normalizeAttribute($object->getScore(), 'Xabbuh\XApi\Model\Score', $context); |
36
|
|
|
} |
37
|
|
|
|
38
|
11 |
|
if (null !== $success = $object->getSuccess()) { |
39
|
2 |
|
$data['success'] = $success; |
40
|
|
|
} |
41
|
|
|
|
42
|
11 |
|
if (null !== $completion = $object->getCompletion()) { |
43
|
2 |
|
$data['completion'] = $completion; |
44
|
|
|
} |
45
|
|
|
|
46
|
11 |
|
if (null !== $response = $object->getResponse()) { |
47
|
2 |
|
$data['response'] = $response; |
48
|
|
|
} |
49
|
|
|
|
50
|
11 |
|
if (null !== $duration = $object->getDuration()) { |
51
|
3 |
|
$data['duration'] = $duration; |
52
|
|
|
} |
53
|
|
|
|
54
|
11 |
|
if (null !== $extensions = $object->getExtensions()) { |
|
|
|
|
55
|
|
|
$data['extensions'] = $this->normalizeAttribute($extensions, 'Xabbuh\XApi\Model\Extensions', $context); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if (empty($data)) { |
59
|
|
|
return new \stdClass(); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $data; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
74 |
|
public function supportsNormalization($data, $format = null) |
69
|
|
|
{ |
70
|
74 |
|
return $data instanceof Result; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
11 |
|
public function denormalize($data, $class, $format = null, array $context = array()) |
77
|
|
|
{ |
78
|
11 |
|
$score = isset($data['score']) ? $this->denormalizeData($data['score'], 'Xabbuh\XApi\Model\Score', $format, $context) : null; |
79
|
11 |
|
$success = isset($data['success']) ? $data['success'] : null; |
80
|
11 |
|
$completion = isset($data['completion']) ? $data['completion'] : null; |
81
|
11 |
|
$response = isset($data['response']) ? $data['response'] : null; |
82
|
11 |
|
$duration = isset($data['duration']) ? $data['duration'] : null; |
83
|
11 |
|
$extensions = isset($data['extensions']) ? $this->denormalizeData($data['extensions'], 'Xabbuh\XApi\Model\Extensions', $format, $context) : null; |
84
|
|
|
|
85
|
11 |
|
return new Result($score, $success, $completion, $response, $duration, $extensions); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
75 |
|
public function supportsDenormalization($data, $type, $format = null) |
92
|
|
|
{ |
93
|
75 |
|
return 'Xabbuh\XApi\Model\Result' === $type; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.