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\StatementResult; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Christian Flothmann <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
final class StatementResultNormalizer extends Normalizer |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function normalize($object, $format = null, array $context = array()) |
25
|
|
|
{ |
26
|
|
|
if (!$object instanceof StatementResult) { |
27
|
|
|
return null; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$data = array( |
31
|
|
|
'statements' => array(), |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
foreach ($object->getStatements() as $statement) { |
35
|
|
|
$data['statements'][] = $this->normalizeAttribute($statement, $format, $context); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if (null !== $moreUrlPath = $object->getMoreUrlPath()) { |
39
|
|
|
$data['more'] = $moreUrlPath; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return $data; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
public function supportsNormalization($data, $format = null) |
49
|
|
|
{ |
50
|
|
|
return $data instanceof StatementResult; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
public function denormalize($data, $class, $format = null, array $context = array()) |
57
|
|
|
{ |
58
|
|
|
$statements = $this->denormalizeData($data['statements'], 'Xabbuh\XApi\Model\Statement[]'); |
59
|
|
|
|
60
|
|
|
return new StatementResult($statements, isset($data['more']) ? $data['more'] : null); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
public function supportsDenormalization($data, $type, $format = null) |
67
|
|
|
{ |
68
|
|
|
return 'Xabbuh\XApi\Model\StatementResult' === $type; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|