1: <?php
2:
3: declare(strict_types=1);
4:
5: /*
6: * This file has been auto generated by Jane,
7: *
8: * Do no edit it directly.
9: */
10:
11: namespace NxSys\Library\Clients\Brex\API\Budgets\Normalizer;
12:
13: use Jane\Component\JsonSchemaRuntime\Reference;
14: use NxSys\Library\Clients\Brex\API\Budgets\Runtime\Normalizer\CheckArray;
15: use NxSys\Library\Clients\Brex\API\Budgets\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 UpdateBudgetRequestNormalizer 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\\Budgets\\Model\\UpdateBudgetRequest';
33: }
34:
35: public function supportsNormalization($data, $format = null): bool
36: {
37: return is_object($data) && get_class($data) === 'NxSys\\Library\\Clients\\Brex\\API\\Budgets\\Model\\UpdateBudgetRequest';
38: }
39:
40: /**
41: * @return mixed
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\Budgets\Model\UpdateBudgetRequest();
52: if (null === $data || false === \is_array($data)) {
53: return $object;
54: }
55: if (\array_key_exists('name', $data) && $data['name'] !== null) {
56: $object->setName($data['name']);
57: unset($data['name']);
58: } elseif (\array_key_exists('name', $data) && $data['name'] === null) {
59: $object->setName(null);
60: }
61: if (\array_key_exists('description', $data) && $data['description'] !== null) {
62: $object->setDescription($data['description']);
63: unset($data['description']);
64: } elseif (\array_key_exists('description', $data) && $data['description'] === null) {
65: $object->setDescription(null);
66: }
67: if (\array_key_exists('owner_user_ids', $data) && $data['owner_user_ids'] !== null) {
68: $values = [];
69: foreach ($data['owner_user_ids'] as $value) {
70: $values[] = $value;
71: }
72: $object->setOwnerUserIds($values);
73: unset($data['owner_user_ids']);
74: } elseif (\array_key_exists('owner_user_ids', $data) && $data['owner_user_ids'] === null) {
75: $object->setOwnerUserIds(null);
76: }
77: if (\array_key_exists('member_user_ids', $data) && $data['member_user_ids'] !== null) {
78: $values_1 = [];
79: foreach ($data['member_user_ids'] as $value_1) {
80: $values_1[] = $value_1;
81: }
82: $object->setMemberUserIds($values_1);
83: unset($data['member_user_ids']);
84: } elseif (\array_key_exists('member_user_ids', $data) && $data['member_user_ids'] === null) {
85: $object->setMemberUserIds(null);
86: }
87: if (\array_key_exists('limit', $data)) {
88: $object->setLimit($this->denormalizer->denormalize($data['limit'], 'NxSys\\Library\\Clients\\Brex\\API\\Budgets\\Model\\UpdateBudgetRequestLimit', 'json', $context));
89: unset($data['limit']);
90: }
91: if (\array_key_exists('limit_type', $data)) {
92: $object->setLimitType($data['limit_type']);
93: unset($data['limit_type']);
94: }
95: if (\array_key_exists('spend_type', $data)) {
96: $object->setSpendType($data['spend_type']);
97: unset($data['spend_type']);
98: }
99: if (\array_key_exists('start_date', $data) && $data['start_date'] !== null) {
100: $object->setStartDate(\DateTime::createFromFormat('Y-m-d', $data['start_date'])->setTime(0, 0, 0));
101: unset($data['start_date']);
102: } elseif (\array_key_exists('start_date', $data) && $data['start_date'] === null) {
103: $object->setStartDate(null);
104: }
105: if (\array_key_exists('end_date', $data) && $data['end_date'] !== null) {
106: $object->setEndDate(\DateTime::createFromFormat('Y-m-d', $data['end_date'])->setTime(0, 0, 0));
107: unset($data['end_date']);
108: } elseif (\array_key_exists('end_date', $data) && $data['end_date'] === null) {
109: $object->setEndDate(null);
110: }
111: foreach ($data as $key => $value_2) {
112: if (preg_match('/.*/', (string) $key)) {
113: $object[$key] = $value_2;
114: }
115: }
116:
117: return $object;
118: }
119:
120: /**
121: * @return array|string|int|float|bool|\ArrayObject|null
122: */
123: public function normalize($object, $format = null, array $context = [])
124: {
125: $data = [];
126: if ($object->isInitialized('name') && null !== $object->getName()) {
127: $data['name'] = $object->getName();
128: }
129: if ($object->isInitialized('description') && null !== $object->getDescription()) {
130: $data['description'] = $object->getDescription();
131: }
132: if ($object->isInitialized('ownerUserIds') && null !== $object->getOwnerUserIds()) {
133: $values = [];
134: foreach ($object->getOwnerUserIds() as $value) {
135: $values[] = $value;
136: }
137: $data['owner_user_ids'] = $values;
138: }
139: if ($object->isInitialized('memberUserIds') && null !== $object->getMemberUserIds()) {
140: $values_1 = [];
141: foreach ($object->getMemberUserIds() as $value_1) {
142: $values_1[] = $value_1;
143: }
144: $data['member_user_ids'] = $values_1;
145: }
146: if ($object->isInitialized('limit') && null !== $object->getLimit()) {
147: $data['limit'] = $this->normalizer->normalize($object->getLimit(), 'json', $context);
148: }
149: if ($object->isInitialized('limitType') && null !== $object->getLimitType()) {
150: $data['limit_type'] = $object->getLimitType();
151: }
152: if ($object->isInitialized('spendType') && null !== $object->getSpendType()) {
153: $data['spend_type'] = $object->getSpendType();
154: }
155: if ($object->isInitialized('startDate') && null !== $object->getStartDate()) {
156: $data['start_date'] = $object->getStartDate()->format('Y-m-d');
157: }
158: if ($object->isInitialized('endDate') && null !== $object->getEndDate()) {
159: $data['end_date'] = $object->getEndDate()->format('Y-m-d');
160: }
161: foreach ($object as $key => $value_2) {
162: if (preg_match('/.*/', (string) $key)) {
163: $data[$key] = $value_2;
164: }
165: }
166:
167: return $data;
168: }
169: }
170: