1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | namespace NxSys\Library\Clients\Brex\API\Team\Normalizer; |
12: | |
13: | use Jane\Component\JsonSchemaRuntime\Reference; |
14: | use NxSys\Library\Clients\Brex\API\Team\Runtime\Normalizer\CheckArray; |
15: | use NxSys\Library\Clients\Brex\API\Team\Runtime\Normalizer\ValidatorTrait; |
16: | use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; |
17: | use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; |
18: | use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
19: | use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; |
20: | use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; |
21: | use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
22: | |
23: | class UpdateUserRequestNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface |
24: | { |
25: | use DenormalizerAwareTrait; |
26: | use NormalizerAwareTrait; |
27: | use CheckArray; |
28: | use ValidatorTrait; |
29: | |
30: | public function supportsDenormalization($data, $type, $format = null): bool |
31: | { |
32: | return $type === 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\UpdateUserRequest'; |
33: | } |
34: | |
35: | public function supportsNormalization($data, $format = null): bool |
36: | { |
37: | return is_object($data) && get_class($data) === 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\UpdateUserRequest'; |
38: | } |
39: | |
40: | |
41: | |
42: | |
43: | public function denormalize($data, $class, $format = null, array $context = []) |
44: | { |
45: | if (isset($data['$ref'])) { |
46: | return new Reference($data['$ref'], $context['document-origin']); |
47: | } |
48: | if (isset($data['$recursiveRef'])) { |
49: | return new Reference($data['$recursiveRef'], $context['document-origin']); |
50: | } |
51: | $object = new \NxSys\Library\Clients\Brex\API\Team\Model\UpdateUserRequest(); |
52: | if (null === $data || false === \is_array($data)) { |
53: | return $object; |
54: | } |
55: | if (\array_key_exists('status', $data)) { |
56: | $object->setStatus($data['status']); |
57: | unset($data['status']); |
58: | } |
59: | if (\array_key_exists('manager_id', $data) && $data['manager_id'] !== null) { |
60: | $object->setManagerId($data['manager_id']); |
61: | unset($data['manager_id']); |
62: | } elseif (\array_key_exists('manager_id', $data) && $data['manager_id'] === null) { |
63: | $object->setManagerId(null); |
64: | } |
65: | if (\array_key_exists('department_id', $data) && $data['department_id'] !== null) { |
66: | $object->setDepartmentId($data['department_id']); |
67: | unset($data['department_id']); |
68: | } elseif (\array_key_exists('department_id', $data) && $data['department_id'] === null) { |
69: | $object->setDepartmentId(null); |
70: | } |
71: | if (\array_key_exists('location_id', $data) && $data['location_id'] !== null) { |
72: | $object->setLocationId($data['location_id']); |
73: | unset($data['location_id']); |
74: | } elseif (\array_key_exists('location_id', $data) && $data['location_id'] === null) { |
75: | $object->setLocationId(null); |
76: | } |
77: | foreach ($data as $key => $value) { |
78: | if (preg_match('/.*/', (string) $key)) { |
79: | $object[$key] = $value; |
80: | } |
81: | } |
82: | |
83: | return $object; |
84: | } |
85: | |
86: | |
87: | |
88: | |
89: | public function normalize($object, $format = null, array $context = []) |
90: | { |
91: | $data = []; |
92: | if ($object->isInitialized('status') && null !== $object->getStatus()) { |
93: | $data['status'] = $object->getStatus(); |
94: | } |
95: | if ($object->isInitialized('managerId') && null !== $object->getManagerId()) { |
96: | $data['manager_id'] = $object->getManagerId(); |
97: | } |
98: | if ($object->isInitialized('departmentId') && null !== $object->getDepartmentId()) { |
99: | $data['department_id'] = $object->getDepartmentId(); |
100: | } |
101: | if ($object->isInitialized('locationId') && null !== $object->getLocationId()) { |
102: | $data['location_id'] = $object->getLocationId(); |
103: | } |
104: | foreach ($object as $key => $value) { |
105: | if (preg_match('/.*/', (string) $key)) { |
106: | $data[$key] = $value; |
107: | } |
108: | } |
109: | |
110: | return $data; |
111: | } |
112: | } |
113: | |