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 TaskNormalizer 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\\Task'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function supportsNormalization($data, $format = null) |
30
|
|
|
{ |
31
|
|
|
return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\Task'; |
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\Task(); |
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, 'active') && $data->{'active'} !== null) { |
46
|
|
|
$object->setActive($data->{'active'}); |
47
|
|
|
} elseif (property_exists($data, 'active') && $data->{'active'} === null) { |
48
|
|
|
$object->setActive(null); |
49
|
|
|
} |
50
|
|
|
if (property_exists($data, 'name') && $data->{'name'} !== null) { |
51
|
|
|
$object->setName($data->{'name'}); |
52
|
|
|
} elseif (property_exists($data, 'name') && $data->{'name'} === null) { |
53
|
|
|
$object->setName(null); |
54
|
|
|
} |
55
|
|
|
if (property_exists($data, 'code') && $data->{'code'} !== null) { |
56
|
|
|
$object->setCode($data->{'code'}); |
57
|
|
|
} elseif (property_exists($data, 'code') && $data->{'code'} === null) { |
58
|
|
|
$object->setCode(null); |
59
|
|
|
} |
60
|
|
|
if (property_exists($data, 'hourlyRate') && $data->{'hourlyRate'} !== null) { |
61
|
|
|
$object->setHourlyRate($data->{'hourlyRate'}); |
62
|
|
|
} elseif (property_exists($data, 'hourlyRate') && $data->{'hourlyRate'} === null) { |
63
|
|
|
$object->setHourlyRate(null); |
64
|
|
|
} |
65
|
|
|
if (property_exists($data, 'billable') && $data->{'billable'} !== null) { |
66
|
|
|
$object->setBillable($data->{'billable'}); |
67
|
|
|
} elseif (property_exists($data, 'billable') && $data->{'billable'} === null) { |
68
|
|
|
$object->setBillable(null); |
69
|
|
|
} |
70
|
|
|
if (property_exists($data, 'common') && $data->{'common'} !== null) { |
71
|
|
|
$object->setCommon($data->{'common'}); |
72
|
|
|
} elseif (property_exists($data, 'common') && $data->{'common'} === null) { |
73
|
|
|
$object->setCommon(null); |
74
|
|
|
} |
75
|
|
|
if (property_exists($data, 'unspecified') && $data->{'unspecified'} !== null) { |
76
|
|
|
$object->setUnspecified($data->{'unspecified'}); |
77
|
|
|
} elseif (property_exists($data, 'unspecified') && $data->{'unspecified'} === null) { |
78
|
|
|
$object->setUnspecified(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->getActive()) { |
93
|
|
|
$data->{'active'} = $object->getActive(); |
94
|
|
|
} else { |
95
|
|
|
$data->{'active'} = null; |
96
|
|
|
} |
97
|
|
|
if (null !== $object->getName()) { |
98
|
|
|
$data->{'name'} = $object->getName(); |
99
|
|
|
} else { |
100
|
|
|
$data->{'name'} = null; |
101
|
|
|
} |
102
|
|
|
if (null !== $object->getCode()) { |
103
|
|
|
$data->{'code'} = $object->getCode(); |
104
|
|
|
} else { |
105
|
|
|
$data->{'code'} = null; |
106
|
|
|
} |
107
|
|
|
if (null !== $object->getHourlyRate()) { |
108
|
|
|
$data->{'hourlyRate'} = $object->getHourlyRate(); |
109
|
|
|
} else { |
110
|
|
|
$data->{'hourlyRate'} = null; |
111
|
|
|
} |
112
|
|
|
if (null !== $object->getBillable()) { |
113
|
|
|
$data->{'billable'} = $object->getBillable(); |
114
|
|
|
} else { |
115
|
|
|
$data->{'billable'} = null; |
116
|
|
|
} |
117
|
|
|
if (null !== $object->getCommon()) { |
118
|
|
|
$data->{'common'} = $object->getCommon(); |
119
|
|
|
} else { |
120
|
|
|
$data->{'common'} = null; |
121
|
|
|
} |
122
|
|
|
if (null !== $object->getUnspecified()) { |
123
|
|
|
$data->{'unspecified'} = $object->getUnspecified(); |
124
|
|
|
} else { |
125
|
|
|
$data->{'unspecified'} = null; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $data; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|