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 ProjectNoteNormalizer 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\\ProjectNote'; |
||
28 | } |
||
29 | |||
30 | public function supportsNormalization($data, $format = null) |
||
31 | { |
||
32 | return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\ProjectNote'; |
||
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\ProjectNote(); |
||
41 | if (property_exists($data, 'id')) { |
||
42 | $object->setId($data->{'id'}); |
||
43 | } |
||
44 | if (property_exists($data, 'description')) { |
||
45 | $object->setDescription($data->{'description'}); |
||
46 | } |
||
47 | if (property_exists($data, 'date')) { |
||
48 | $object->setDate(\DateTime::createFromFormat('Y-m-d\\TH:i:sP', $data->{'date'})); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
49 | } |
||
50 | if (property_exists($data, 'projectId')) { |
||
51 | $object->setProjectId($data->{'projectId'}); |
||
52 | } |
||
53 | |||
54 | return $object; |
||
55 | } |
||
56 | |||
57 | public function normalize($object, $format = null, array $context = []) |
||
58 | { |
||
59 | $data = new \stdClass(); |
||
60 | if (null !== $object->getId()) { |
||
61 | $data->{'id'} = $object->getId(); |
||
62 | } |
||
63 | if (null !== $object->getDescription()) { |
||
64 | $data->{'description'} = $object->getDescription(); |
||
65 | } |
||
66 | if (null !== $object->getDate()) { |
||
67 | $data->{'date'} = $object->getDate()->format('Y-m-d\\TH:i:sP'); |
||
68 | } |
||
69 | if (null !== $object->getProjectId()) { |
||
70 | $data->{'projectId'} = $object->getProjectId(); |
||
71 | } |
||
72 | |||
73 | return $data; |
||
74 | } |
||
75 | } |
||
76 |