-
Notifications
You must be signed in to change notification settings - Fork 1
/
RegistrationJsonDeserializer.php
69 lines (59 loc) · 2.07 KB
/
RegistrationJsonDeserializer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace CultuurNet\UiTPASBeheer\UiTPAS\Registration;
use CultuurNet\Deserializer\JSONDeserializer;
use CultuurNet\UiTPASBeheer\Exception\MissingPropertyException;
use CultuurNet\UiTPASBeheer\KansenStatuut\KansenStatuutJsonDeserializer;
use CultuurNet\UiTPASBeheer\User\Properties\Uid;
use CultuurNet\UiTPASBeheer\PassHolder\VoucherNumber;
use CultuurNet\UiTPASBeheer\UiTPAS\Price\PurchaseReason;
use ValueObjects\StringLiteral\StringLiteral;
class RegistrationJsonDeserializer extends JSONDeserializer
{
/**
* @var KansenStatuutJsonDeserializer
*/
protected $kansenStatuutJsonDeserializer;
/**
* @param KansenStatuutJsonDeserializer $kansenStatuutJsonDeserializer
*/
public function __construct(KansenStatuutJsonDeserializer $kansenStatuutJsonDeserializer)
{
$this->kansenStatuutJsonDeserializer = $kansenStatuutJsonDeserializer;
}
/**
* @param StringLiteral $data
* @return Registration
*
* @throws MissingPropertyException
* When passholderUid or reason are missing.
*/
public function deserialize(StringLiteral $data)
{
$data = parent::deserialize($data);
if (empty($data->passholderUid)) {
throw new MissingPropertyException('passholderUid');
}
if (empty($data->reason)) {
throw new MissingPropertyException('reason');
}
$registration = new Registration(
new Uid((string) $data->passholderUid),
PurchaseReason::get($data->reason)
);
if (isset($data->kansenStatuut)) {
$registration = $registration->withKansenStatuut(
$this->kansenStatuutJsonDeserializer->deserialize(
new StringLiteral(
json_encode($data->kansenStatuut)
)
)
);
}
if (isset($data->voucherNumber)) {
$registration = $registration->withVoucherNumber(
new VoucherNumber((string) $data->voucherNumber)
);
}
return $registration;
}
}