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\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 InvoiceRowNormalizer 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\\Model\\InvoiceRow'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function supportsNormalization($data, $format = null) |
31
|
|
|
{ |
32
|
|
|
return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\InvoiceRow'; |
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\Model\InvoiceRow(); |
41
|
|
|
if (property_exists($data, 'id')) { |
42
|
|
|
$object->setId($data->{'id'}); |
43
|
|
|
} |
44
|
|
|
if (property_exists($data, 'invoiceId')) { |
45
|
|
|
$object->setInvoiceId($data->{'invoiceId'}); |
46
|
|
|
} |
47
|
|
|
if (property_exists($data, 'description')) { |
48
|
|
|
$object->setDescription($data->{'description'}); |
49
|
|
|
} |
50
|
|
|
if (property_exists($data, 'quantity')) { |
51
|
|
|
$object->setQuantity($data->{'quantity'}); |
52
|
|
|
} |
53
|
|
|
if (property_exists($data, 'price')) { |
54
|
|
|
$object->setPrice($data->{'price'}); |
55
|
|
|
} |
56
|
|
|
if (property_exists($data, 'tax')) { |
57
|
|
|
$object->setTax($data->{'tax'}); |
58
|
|
|
} |
59
|
|
|
if (property_exists($data, 'total')) { |
60
|
|
|
$object->setTotal($data->{'total'}); |
61
|
|
|
} |
62
|
|
|
if (property_exists($data, 'index')) { |
63
|
|
|
$object->setIndex($data->{'index'}); |
64
|
|
|
} |
65
|
|
|
if (property_exists($data, 'code')) { |
66
|
|
|
$object->setCode($data->{'code'}); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $object; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function normalize($object, $format = null, array $context = []) |
73
|
|
|
{ |
74
|
|
|
$data = new \stdClass(); |
75
|
|
|
if (null !== $object->getId()) { |
76
|
|
|
$data->{'id'} = $object->getId(); |
77
|
|
|
} |
78
|
|
|
if (null !== $object->getInvoiceId()) { |
79
|
|
|
$data->{'invoiceId'} = $object->getInvoiceId(); |
80
|
|
|
} |
81
|
|
|
if (null !== $object->getDescription()) { |
82
|
|
|
$data->{'description'} = $object->getDescription(); |
83
|
|
|
} |
84
|
|
|
if (null !== $object->getQuantity()) { |
85
|
|
|
$data->{'quantity'} = $object->getQuantity(); |
86
|
|
|
} |
87
|
|
|
if (null !== $object->getPrice()) { |
88
|
|
|
$data->{'price'} = $object->getPrice(); |
89
|
|
|
} |
90
|
|
|
if (null !== $object->getTax()) { |
91
|
|
|
$data->{'tax'} = $object->getTax(); |
92
|
|
|
} |
93
|
|
|
if (null !== $object->getTotal()) { |
94
|
|
|
$data->{'total'} = $object->getTotal(); |
95
|
|
|
} |
96
|
|
|
if (null !== $object->getIndex()) { |
97
|
|
|
$data->{'index'} = $object->getIndex(); |
98
|
|
|
} |
99
|
|
|
if (null !== $object->getCode()) { |
100
|
|
|
$data->{'code'} = $object->getCode(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $data; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|