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\Client\Normalizer; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\Serializer\Exception\InvalidArgumentException; |
13
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; |
14
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; |
15
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
16
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; |
17
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; |
18
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
19
|
|
|
|
20
|
|
|
class ExpenseNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface |
21
|
|
|
{ |
22
|
|
|
use DenormalizerAwareTrait; |
23
|
|
|
use NormalizerAwareTrait; |
24
|
|
|
|
25
|
|
|
public function supportsDenormalization($data, $type, $format = null) |
26
|
|
|
{ |
27
|
|
|
return $type === 'ConnectHolland\\TimechimpBundle\\Api\\Client\\Model\\Expense'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function supportsNormalization($data, $format = null) |
31
|
|
|
{ |
32
|
|
|
return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Client\\Model\\Expense'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function denormalize($data, $class, $format = null, array $context = []) |
36
|
|
|
{ |
37
|
|
|
if (!is_object($data)) { |
38
|
|
|
throw new InvalidArgumentException(sprintf('Given $data is not an object (%s given). We need an object in order to continue denormalize method.', gettype($data))); |
39
|
|
|
} |
40
|
|
|
$object = new \ConnectHolland\TimechimpBundle\Api\Client\Model\Expense(); |
41
|
|
|
if (property_exists($data, 'id')) { |
42
|
|
|
$object->setId($data->{'id'}); |
43
|
|
|
} |
44
|
|
|
if (property_exists($data, 'customerId')) { |
45
|
|
|
$object->setCustomerId($data->{'customerId'}); |
46
|
|
|
} |
47
|
|
|
if (property_exists($data, 'customerName')) { |
48
|
|
|
$object->setCustomerName($data->{'customerName'}); |
49
|
|
|
} |
50
|
|
|
if (property_exists($data, 'projectId')) { |
51
|
|
|
$object->setProjectId($data->{'projectId'}); |
52
|
|
|
} |
53
|
|
|
if (property_exists($data, 'projectName')) { |
54
|
|
|
$object->setProjectName($data->{'projectName'}); |
55
|
|
|
} |
56
|
|
|
if (property_exists($data, 'categoryName')) { |
57
|
|
|
$object->setCategoryName($data->{'categoryName'}); |
58
|
|
|
} |
59
|
|
|
if (property_exists($data, 'categoryId')) { |
60
|
|
|
$object->setCategoryId($data->{'categoryId'}); |
61
|
|
|
} |
62
|
|
|
if (property_exists($data, 'userId')) { |
63
|
|
|
$object->setUserId($data->{'userId'}); |
64
|
|
|
} |
65
|
|
|
if (property_exists($data, 'userDisplayName')) { |
66
|
|
|
$object->setUserDisplayName($data->{'userDisplayName'}); |
67
|
|
|
} |
68
|
|
|
if (property_exists($data, 'date')) { |
69
|
|
|
$object->setDate(\DateTime::createFromFormat('Y-m-d\\TH:i:sP', $data->{'date'})); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
if (property_exists($data, 'notes')) { |
72
|
|
|
$object->setNotes($data->{'notes'}); |
73
|
|
|
} |
74
|
|
|
if (property_exists($data, 'attachment')) { |
75
|
|
|
$object->setAttachment($data->{'attachment'}); |
76
|
|
|
} |
77
|
|
|
if (property_exists($data, 'quantity')) { |
78
|
|
|
$object->setQuantity($data->{'quantity'}); |
79
|
|
|
} |
80
|
|
|
if (property_exists($data, 'rate')) { |
81
|
|
|
$object->setRate($data->{'rate'}); |
82
|
|
|
} |
83
|
|
|
if (property_exists($data, 'tax')) { |
84
|
|
|
$object->setTax($data->{'tax'}); |
85
|
|
|
} |
86
|
|
|
if (property_exists($data, 'billable')) { |
87
|
|
|
$object->setBillable($data->{'billable'}); |
88
|
|
|
} |
89
|
|
|
if (property_exists($data, 'status')) { |
90
|
|
|
$object->setStatus($data->{'status'}); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $object; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function normalize($object, $format = null, array $context = []) |
97
|
|
|
{ |
98
|
|
|
$data = new \stdClass(); |
99
|
|
|
if (null !== $object->getId()) { |
100
|
|
|
$data->{'id'} = $object->getId(); |
101
|
|
|
} |
102
|
|
|
if (null !== $object->getCustomerId()) { |
103
|
|
|
$data->{'customerId'} = $object->getCustomerId(); |
104
|
|
|
} |
105
|
|
|
if (null !== $object->getCustomerName()) { |
106
|
|
|
$data->{'customerName'} = $object->getCustomerName(); |
107
|
|
|
} |
108
|
|
|
if (null !== $object->getProjectId()) { |
109
|
|
|
$data->{'projectId'} = $object->getProjectId(); |
110
|
|
|
} |
111
|
|
|
if (null !== $object->getProjectName()) { |
112
|
|
|
$data->{'projectName'} = $object->getProjectName(); |
113
|
|
|
} |
114
|
|
|
if (null !== $object->getCategoryName()) { |
115
|
|
|
$data->{'categoryName'} = $object->getCategoryName(); |
116
|
|
|
} |
117
|
|
|
if (null !== $object->getCategoryId()) { |
118
|
|
|
$data->{'categoryId'} = $object->getCategoryId(); |
119
|
|
|
} |
120
|
|
|
if (null !== $object->getUserId()) { |
121
|
|
|
$data->{'userId'} = $object->getUserId(); |
122
|
|
|
} |
123
|
|
|
if (null !== $object->getUserDisplayName()) { |
124
|
|
|
$data->{'userDisplayName'} = $object->getUserDisplayName(); |
125
|
|
|
} |
126
|
|
|
if (null !== $object->getDate()) { |
127
|
|
|
$data->{'date'} = $object->getDate()->format('Y-m-d\\TH:i:sP'); |
128
|
|
|
} |
129
|
|
|
if (null !== $object->getNotes()) { |
130
|
|
|
$data->{'notes'} = $object->getNotes(); |
131
|
|
|
} |
132
|
|
|
if (null !== $object->getAttachment()) { |
133
|
|
|
$data->{'attachment'} = $object->getAttachment(); |
134
|
|
|
} |
135
|
|
|
if (null !== $object->getQuantity()) { |
136
|
|
|
$data->{'quantity'} = $object->getQuantity(); |
137
|
|
|
} |
138
|
|
|
if (null !== $object->getRate()) { |
139
|
|
|
$data->{'rate'} = $object->getRate(); |
140
|
|
|
} |
141
|
|
|
if (null !== $object->getTax()) { |
142
|
|
|
$data->{'tax'} = $object->getTax(); |
143
|
|
|
} |
144
|
|
|
if (null !== $object->getBillable()) { |
145
|
|
|
$data->{'billable'} = $object->getBillable(); |
146
|
|
|
} |
147
|
|
|
if (null !== $object->getStatus()) { |
148
|
|
|
$data->{'status'} = $object->getStatus(); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return $data; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|