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\Symfony; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Serializer\SerializerInterface; |
15
|
|
|
use Xabbuh\XApi\Model\Statement; |
16
|
|
|
use Xabbuh\XApi\Serializer\StatementSerializerInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Serializes and deserializes {@link Statement statements} using the Symfony Serializer component. |
20
|
|
|
* |
21
|
|
|
* @author Christian Flothmann <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
final class StatementSerializer implements StatementSerializerInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var SerializerInterface The underlying serializer |
27
|
|
|
*/ |
28
|
|
|
private $serializer; |
29
|
|
|
|
30
|
|
|
public function __construct(SerializerInterface $serializer) |
31
|
|
|
{ |
32
|
|
|
$this->serializer = $serializer; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritDoc} |
37
|
|
|
*/ |
38
|
|
|
public function serializeStatement(Statement $statement) |
39
|
|
|
{ |
40
|
|
|
return $this->serializer->serialize($statement, 'json'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritDoc} |
45
|
|
|
*/ |
46
|
|
|
public function serializeStatements(array $statements) |
47
|
|
|
{ |
48
|
|
|
return $this->serializer->serialize($statements, 'json'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritDoc} |
53
|
|
|
*/ |
54
|
|
|
public function deserializeStatement($data, array $attachments = array()) |
55
|
|
|
{ |
56
|
|
|
return $this->serializer->deserialize( |
|
|
|
|
57
|
|
|
$data, |
58
|
|
|
'Xabbuh\XApi\Model\Statement', |
59
|
|
|
'json', |
60
|
|
|
array( |
61
|
|
|
'xapi_attachments' => $attachments, |
62
|
|
|
) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritDoc} |
68
|
|
|
*/ |
69
|
|
|
public function deserializeStatements($data, array $attachments = array()) |
70
|
|
|
{ |
71
|
|
|
return $this->serializer->deserialize( |
|
|
|
|
72
|
|
|
$data, |
73
|
|
|
'Xabbuh\XApi\Model\Statement[]', |
74
|
|
|
'json', |
75
|
|
|
array( |
76
|
|
|
'xapi_attachments' => $attachments, |
77
|
|
|
) |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|