|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the timechimp bundle package. |
|
7
|
|
|
* (c) Connect Holland. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace ConnectHolland\TimechimpBundle\Api\Normalizer; |
|
11
|
|
|
|
|
12
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; |
|
13
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; |
|
14
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
|
15
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; |
|
16
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; |
|
17
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
|
18
|
|
|
|
|
19
|
|
|
class ProjectSubscriptionNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface |
|
20
|
|
|
{ |
|
21
|
|
|
use DenormalizerAwareTrait; |
|
22
|
|
|
use NormalizerAwareTrait; |
|
23
|
|
|
|
|
24
|
|
|
public function supportsDenormalization($data, $type, $format = null) |
|
25
|
|
|
{ |
|
26
|
|
|
return $type === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\ProjectSubscription'; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function supportsNormalization($data, $format = null) |
|
30
|
|
|
{ |
|
31
|
|
|
return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\ProjectSubscription'; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function denormalize($data, $class, $format = null, array $context = []) |
|
35
|
|
|
{ |
|
36
|
|
|
if (!is_object($data)) { |
|
37
|
|
|
return null; |
|
38
|
|
|
} |
|
39
|
|
|
$object = new \ConnectHolland\TimechimpBundle\Api\Model\ProjectSubscription(); |
|
40
|
|
|
if (property_exists($data, 'id') && $data->{'id'} !== null) { |
|
41
|
|
|
$object->setId($data->{'id'}); |
|
42
|
|
|
} elseif (property_exists($data, 'id') && $data->{'id'} === null) { |
|
43
|
|
|
$object->setId(null); |
|
44
|
|
|
} |
|
45
|
|
|
if (property_exists($data, 'frequency') && $data->{'frequency'} !== null) { |
|
46
|
|
|
$object->setFrequency($data->{'frequency'}); |
|
47
|
|
|
} elseif (property_exists($data, 'frequency') && $data->{'frequency'} === null) { |
|
48
|
|
|
$object->setFrequency(null); |
|
49
|
|
|
} |
|
50
|
|
|
if (property_exists($data, 'startDate') && $data->{'startDate'} !== null) { |
|
51
|
|
|
$object->setStartDate(\DateTime::createFromFormat('Y-m-d\\TH:i:s', $data->{'startDate'})); |
|
|
|
|
|
|
52
|
|
|
} elseif (property_exists($data, 'startDate') && $data->{'startDate'} === null) { |
|
53
|
|
|
$object->setStartDate(null); |
|
54
|
|
|
} |
|
55
|
|
|
if (property_exists($data, 'endDate') && $data->{'endDate'} !== null) { |
|
56
|
|
|
$object->setEndDate(\DateTime::createFromFormat('Y-m-d\\TH:i:s', $data->{'endDate'})); |
|
|
|
|
|
|
57
|
|
|
} elseif (property_exists($data, 'endDate') && $data->{'endDate'} === null) { |
|
58
|
|
|
$object->setEndDate(null); |
|
59
|
|
|
} |
|
60
|
|
|
if (property_exists($data, 'description') && $data->{'description'} !== null) { |
|
61
|
|
|
$object->setDescription($data->{'description'}); |
|
62
|
|
|
} elseif (property_exists($data, 'description') && $data->{'description'} === null) { |
|
63
|
|
|
$object->setDescription(null); |
|
64
|
|
|
} |
|
65
|
|
|
if (property_exists($data, 'code') && $data->{'code'} !== null) { |
|
66
|
|
|
$object->setCode($data->{'code'}); |
|
67
|
|
|
} elseif (property_exists($data, 'code') && $data->{'code'} === null) { |
|
68
|
|
|
$object->setCode(null); |
|
69
|
|
|
} |
|
70
|
|
|
if (property_exists($data, 'amount') && $data->{'amount'} !== null) { |
|
71
|
|
|
$object->setAmount($data->{'amount'}); |
|
72
|
|
|
} elseif (property_exists($data, 'amount') && $data->{'amount'} === null) { |
|
73
|
|
|
$object->setAmount(null); |
|
74
|
|
|
} |
|
75
|
|
|
if (property_exists($data, 'rate') && $data->{'rate'} !== null) { |
|
76
|
|
|
$object->setRate($data->{'rate'}); |
|
77
|
|
|
} elseif (property_exists($data, 'rate') && $data->{'rate'} === null) { |
|
78
|
|
|
$object->setRate(null); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $object; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function normalize($object, $format = null, array $context = []) |
|
85
|
|
|
{ |
|
86
|
|
|
$data = new \stdClass(); |
|
87
|
|
|
if (null !== $object->getId()) { |
|
88
|
|
|
$data->{'id'} = $object->getId(); |
|
89
|
|
|
} else { |
|
90
|
|
|
$data->{'id'} = null; |
|
91
|
|
|
} |
|
92
|
|
|
if (null !== $object->getFrequency()) { |
|
93
|
|
|
$data->{'frequency'} = $object->getFrequency(); |
|
94
|
|
|
} else { |
|
95
|
|
|
$data->{'frequency'} = null; |
|
96
|
|
|
} |
|
97
|
|
|
if (null !== $object->getStartDate()) { |
|
98
|
|
|
$data->{'startDate'} = $object->getStartDate()->format('Y-m-d\\TH:i:s'); |
|
99
|
|
|
} else { |
|
100
|
|
|
$data->{'startDate'} = null; |
|
101
|
|
|
} |
|
102
|
|
|
if (null !== $object->getEndDate()) { |
|
103
|
|
|
$data->{'endDate'} = $object->getEndDate()->format('Y-m-d\\TH:i:s'); |
|
104
|
|
|
} else { |
|
105
|
|
|
$data->{'endDate'} = null; |
|
106
|
|
|
} |
|
107
|
|
|
if (null !== $object->getDescription()) { |
|
108
|
|
|
$data->{'description'} = $object->getDescription(); |
|
109
|
|
|
} else { |
|
110
|
|
|
$data->{'description'} = null; |
|
111
|
|
|
} |
|
112
|
|
|
if (null !== $object->getCode()) { |
|
113
|
|
|
$data->{'code'} = $object->getCode(); |
|
114
|
|
|
} else { |
|
115
|
|
|
$data->{'code'} = null; |
|
116
|
|
|
} |
|
117
|
|
|
if (null !== $object->getAmount()) { |
|
118
|
|
|
$data->{'amount'} = $object->getAmount(); |
|
119
|
|
|
} else { |
|
120
|
|
|
$data->{'amount'} = null; |
|
121
|
|
|
} |
|
122
|
|
|
if (null !== $object->getRate()) { |
|
123
|
|
|
$data->{'rate'} = $object->getRate(); |
|
124
|
|
|
} else { |
|
125
|
|
|
$data->{'rate'} = null; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return $data; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|