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 CreateBudgetRequestNormalizer 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\\CreateBudgetRequest';
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\\CreateBudgetRequest';
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\CreateBudgetRequest();
52: if (null === $data || false === \is_array($data)) {
53: return $object;
54: }
55: if (\array_key_exists('name', $data)) {
56: $object->setName($data['name']);
57: unset($data['name']);
58: }
59: if (\array_key_exists('description', $data)) {
60: $object->setDescription($data['description']);
61: unset($data['description']);
62: }
63: if (\array_key_exists('parent_budget_id', $data) && $data['parent_budget_id'] !== null) {
64: $object->setParentBudgetId($data['parent_budget_id']);
65: unset($data['parent_budget_id']);
66: } elseif (\array_key_exists('parent_budget_id', $data) && $data['parent_budget_id'] === null) {
67: $object->setParentBudgetId(null);
68: }
69: if (\array_key_exists('owner_user_ids', $data) && $data['owner_user_ids'] !== null) {
70: $values = [];
71: foreach ($data['owner_user_ids'] as $value) {
72: $values[] = $value;
73: }
74: $object->setOwnerUserIds($values);
75: unset($data['owner_user_ids']);
76: } elseif (\array_key_exists('owner_user_ids', $data) && $data['owner_user_ids'] === null) {
77: $object->setOwnerUserIds(null);
78: }
79: if (\array_key_exists('member_user_ids', $data) && $data['member_user_ids'] !== null) {
80: $values_1 = [];
81: foreach ($data['member_user_ids'] as $value_1) {
82: $values_1[] = $value_1;
83: }
84: $object->setMemberUserIds($values_1);
85: unset($data['member_user_ids']);
86: } elseif (\array_key_exists('member_user_ids', $data) && $data['member_user_ids'] === null) {
87: $object->setMemberUserIds(null);
88: }
89: if (\array_key_exists('period_type', $data)) {
90: $object->setPeriodType($data['period_type']);
91: unset($data['period_type']);
92: }
93: if (\array_key_exists('limit', $data)) {
94: $object->setLimit($this->denormalizer->denormalize($data['limit'], 'NxSys\\Library\\Clients\\Brex\\API\\Budgets\\Model\\Money', 'json', $context));
95: unset($data['limit']);
96: }
97: if (\array_key_exists('limit_type', $data)) {
98: $object->setLimitType($data['limit_type']);
99: unset($data['limit_type']);
100: }
101: if (\array_key_exists('spend_type', $data)) {
102: $object->setSpendType($data['spend_type']);
103: unset($data['spend_type']);
104: }
105: if (\array_key_exists('start_date', $data) && $data['start_date'] !== null) {
106: $object->setStartDate(\DateTime::createFromFormat('Y-m-d', $data['start_date'])->setTime(0, 0, 0));
107: unset($data['start_date']);
108: } elseif (\array_key_exists('start_date', $data) && $data['start_date'] === null) {
109: $object->setStartDate(null);
110: }
111: if (\array_key_exists('end_date', $data) && $data['end_date'] !== null) {
112: $object->setEndDate(\DateTime::createFromFormat('Y-m-d', $data['end_date'])->setTime(0, 0, 0));
113: unset($data['end_date']);
114: } elseif (\array_key_exists('end_date', $data) && $data['end_date'] === null) {
115: $object->setEndDate(null);
116: }
117: foreach ($data as $key => $value_2) {
118: if (preg_match('/.*/', (string) $key)) {
119: $object[$key] = $value_2;
120: }
121: }
122:
123: return $object;
124: }
125:
126: /**
127: * @return array|string|int|float|bool|\ArrayObject|null
128: */
129: public function normalize($object, $format = null, array $context = [])
130: {
131: $data = [];
132: if ($object->isInitialized('name') && null !== $object->getName()) {
133: $data['name'] = $object->getName();
134: }
135: if ($object->isInitialized('description') && null !== $object->getDescription()) {
136: $data['description'] = $object->getDescription();
137: }
138: if ($object->isInitialized('parentBudgetId') && null !== $object->getParentBudgetId()) {
139: $data['parent_budget_id'] = $object->getParentBudgetId();
140: }
141: if ($object->isInitialized('ownerUserIds') && null !== $object->getOwnerUserIds()) {
142: $values = [];
143: foreach ($object->getOwnerUserIds() as $value) {
144: $values[] = $value;
145: }
146: $data['owner_user_ids'] = $values;
147: }
148: if ($object->isInitialized('memberUserIds') && null !== $object->getMemberUserIds()) {
149: $values_1 = [];
150: foreach ($object->getMemberUserIds() as $value_1) {
151: $values_1[] = $value_1;
152: }
153: $data['member_user_ids'] = $values_1;
154: }
155: $data['period_type'] = $object->getPeriodType();
156: $data['limit'] = $this->normalizer->normalize($object->getLimit(), 'json', $context);
157: $data['limit_type'] = $object->getLimitType();
158: $data['spend_type'] = $object->getSpendType();
159: if ($object->isInitialized('startDate') && null !== $object->getStartDate()) {
160: $data['start_date'] = $object->getStartDate()->format('Y-m-d');
161: }
162: if ($object->isInitialized('endDate') && null !== $object->getEndDate()) {
163: $data['end_date'] = $object->getEndDate()->format('Y-m-d');
164: }
165: foreach ($object as $key => $value_2) {
166: if (preg_match('/.*/', (string) $key)) {
167: $data[$key] = $value_2;
168: }
169: }
170:
171: return $data;
172: }
173: }
174: