|
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 ProjectSubscriptionNormalizer 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\\ProjectSubscription'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function supportsNormalization($data, $format = null) |
|
31
|
|
|
{ |
|
32
|
|
|
return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\ProjectSubscription'; |
|
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\ProjectSubscription(); |
|
41
|
|
|
if (property_exists($data, 'id')) { |
|
42
|
|
|
$object->setId($data->{'id'}); |
|
43
|
|
|
} |
|
44
|
|
|
if (property_exists($data, 'frequency')) { |
|
45
|
|
|
$object->setFrequency($data->{'frequency'}); |
|
46
|
|
|
} |
|
47
|
|
|
if (property_exists($data, 'startDate')) { |
|
48
|
|
|
$object->setStartDate(\DateTime::createFromFormat('Y-m-d\\TH:i:sP', $data->{'startDate'})); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
if (property_exists($data, 'endDate')) { |
|
51
|
|
|
$object->setEndDate(\DateTime::createFromFormat('Y-m-d\\TH:i:sP', $data->{'endDate'})); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
if (property_exists($data, 'description')) { |
|
54
|
|
|
$object->setDescription($data->{'description'}); |
|
55
|
|
|
} |
|
56
|
|
|
if (property_exists($data, 'code')) { |
|
57
|
|
|
$object->setCode($data->{'code'}); |
|
58
|
|
|
} |
|
59
|
|
|
if (property_exists($data, 'amount')) { |
|
60
|
|
|
$object->setAmount($data->{'amount'}); |
|
61
|
|
|
} |
|
62
|
|
|
if (property_exists($data, 'rate')) { |
|
63
|
|
|
$object->setRate($data->{'rate'}); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $object; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function normalize($object, $format = null, array $context = []) |
|
70
|
|
|
{ |
|
71
|
|
|
$data = new \stdClass(); |
|
72
|
|
|
if (null !== $object->getId()) { |
|
73
|
|
|
$data->{'id'} = $object->getId(); |
|
74
|
|
|
} |
|
75
|
|
|
if (null !== $object->getFrequency()) { |
|
76
|
|
|
$data->{'frequency'} = $object->getFrequency(); |
|
77
|
|
|
} |
|
78
|
|
|
if (null !== $object->getStartDate()) { |
|
79
|
|
|
$data->{'startDate'} = $object->getStartDate()->format('Y-m-d\\TH:i:sP'); |
|
80
|
|
|
} |
|
81
|
|
|
if (null !== $object->getEndDate()) { |
|
82
|
|
|
$data->{'endDate'} = $object->getEndDate()->format('Y-m-d\\TH:i:sP'); |
|
83
|
|
|
} |
|
84
|
|
|
if (null !== $object->getDescription()) { |
|
85
|
|
|
$data->{'description'} = $object->getDescription(); |
|
86
|
|
|
} |
|
87
|
|
|
if (null !== $object->getCode()) { |
|
88
|
|
|
$data->{'code'} = $object->getCode(); |
|
89
|
|
|
} |
|
90
|
|
|
if (null !== $object->getAmount()) { |
|
91
|
|
|
$data->{'amount'} = $object->getAmount(); |
|
92
|
|
|
} |
|
93
|
|
|
if (null !== $object->getRate()) { |
|
94
|
|
|
$data->{'rate'} = $object->getRate(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return $data; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|