1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace MovingImage\Client\VMPro\Subscriber; |
6
|
|
|
|
7
|
|
|
use JMS\Serializer\DeserializationContext; |
8
|
|
|
use JMS\Serializer\GraphNavigatorInterface; |
9
|
|
|
use JMS\Serializer\Handler\SubscribingHandlerInterface; |
10
|
|
|
use JMS\Serializer\JsonDeserializationVisitor; |
11
|
|
|
use MovingImage\Client\VMPro\Entity\Attachment; |
12
|
|
|
|
13
|
|
|
class DeserializeAttachmentSubscriber implements SubscribingHandlerInterface |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Return format: |
18
|
|
|
* |
19
|
|
|
* array( |
20
|
|
|
* array( |
21
|
|
|
* 'direction' => GraphNavigatorInterface::DIRECTION_SERIALIZATION, |
22
|
|
|
* 'format' => 'json', |
23
|
|
|
* 'type' => 'DateTime', |
24
|
|
|
* 'method' => 'serializeDateTimeToJson', |
25
|
|
|
* ), |
26
|
|
|
* ) |
27
|
|
|
* |
28
|
|
|
* The direction and method keys can be omitted. |
29
|
|
|
* |
30
|
|
|
* @return array |
31
|
|
|
* |
32
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint |
33
|
|
|
*/ |
34
|
|
|
public static function getSubscribingMethods() |
35
|
|
|
{ |
36
|
|
|
return [ |
37
|
|
|
[ |
38
|
|
|
'direction' => GraphNavigatorInterface::DIRECTION_DESERIALIZATION, |
39
|
|
|
'format' => 'json', |
40
|
|
|
'type' => Attachment::class, |
41
|
|
|
'method' => 'deserialize', |
42
|
|
|
] |
43
|
|
|
]; |
44
|
|
|
} |
45
|
|
|
public function deserialize(JsonDeserializationVisitor $visitor, array $data, array $type, DeserializationContext $context) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$attachment = new Attachment(); |
48
|
|
|
if (isset($data['data']['id'])) { |
49
|
|
|
$attachment->setId($data['data']['id']); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if (isset($data['data']['fileName'])) { |
53
|
|
|
$attachment->setFileName($data['data']['fileName']); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if (isset($data['data']['downloadUrl'])) { |
57
|
|
|
$attachment->setDownloadUrl($data['data']['downloadUrl']); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if (isset($data['data']['fileSize'])) { |
61
|
|
|
$attachment->setFileSize($data['data']['fileSize']); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if (isset($data['type']['name'])) { |
65
|
|
|
$attachment->setType($data['type']['name']); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $attachment; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.