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\Exception\LogicException; |
15
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
16
|
|
|
use Symfony\Component\Serializer\SerializerAwareInterface; |
17
|
|
|
use Symfony\Component\Serializer\SerializerInterface; |
18
|
|
|
use Xabbuh\XApi\Model\Attachment; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Denormalizes PHP arrays to {@link Attachment} objects. |
22
|
|
|
* |
23
|
|
|
* @author Christian Flothmann <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
final class AttachmentNormalizer implements DenormalizerInterface, SerializerAwareInterface |
26
|
|
|
{ |
27
|
|
|
private $serializer; |
28
|
|
|
|
29
|
368 |
|
public function setSerializer(SerializerInterface $serializer) |
30
|
|
|
{ |
31
|
368 |
|
$this->serializer = $serializer; |
32
|
368 |
|
} |
33
|
|
|
|
34
|
4 |
|
public function denormalize($data, $class, $format = null, array $context = array()) |
35
|
|
|
{ |
36
|
4 |
|
if (!$this->serializer instanceof DenormalizerInterface) { |
37
|
|
|
throw new LogicException('Cannot denormalize because the injected serializer is not a denormalizer.'); |
38
|
|
|
} |
39
|
|
|
|
40
|
4 |
|
$display = $this->serializer->denormalize($data['display'], 'Xabbuh\XApi\Model\LanguageMap', $format, $context); |
41
|
4 |
|
$description = null; |
42
|
4 |
|
$fileUrl = isset($data['fileUrl']) ? $data['fileUrl'] : null; |
43
|
|
|
|
44
|
4 |
|
if (isset($data['description'])) { |
45
|
|
|
$description = $this->serializer->denormalize($data['description'], 'Xabbuh\XApi\Model\LanguageMap', $format, $context); |
46
|
|
|
} |
47
|
|
|
|
48
|
4 |
|
return new Attachment($data['usageType'], $data['contentType'], $data['length'], $data['sha2'], $display, $description, $fileUrl); |
49
|
|
|
} |
50
|
|
|
|
51
|
164 |
|
public function supportsDenormalization($data, $type, $format = null) |
52
|
|
|
{ |
53
|
164 |
|
return 'Xabbuh\XApi\Model\Attachment' === $type; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|