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\Payments\Normalizer;
12:
13: use Jane\Component\JsonSchemaRuntime\Reference;
14: use NxSys\Library\Clients\Brex\API\Payments\Runtime\Normalizer\CheckArray;
15: use NxSys\Library\Clients\Brex\API\Payments\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 TransferNormalizer 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\\Payments\\Model\\Transfer';
33: }
34:
35: public function supportsNormalization($data, $format = null): bool
36: {
37: return is_object($data) && get_class($data) === 'NxSys\\Library\\Clients\\Brex\\API\\Payments\\Model\\Transfer';
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\Payments\Model\Transfer();
52: if (null === $data || false === \is_array($data)) {
53: return $object;
54: }
55: if (\array_key_exists('id', $data)) {
56: $object->setId($data['id']);
57: unset($data['id']);
58: }
59: if (\array_key_exists('counterparty', $data)) {
60: $object->setCounterparty($this->denormalizer->denormalize($data['counterparty'], 'NxSys\\Library\\Clients\\Brex\\API\\Payments\\Model\\TransferCounterparty', 'json', $context));
61: unset($data['counterparty']);
62: }
63: if (\array_key_exists('description', $data) && $data['description'] !== null) {
64: $object->setDescription($data['description']);
65: unset($data['description']);
66: } elseif (\array_key_exists('description', $data) && $data['description'] === null) {
67: $object->setDescription(null);
68: }
69: if (\array_key_exists('payment_type', $data)) {
70: $object->setPaymentType($data['payment_type']);
71: unset($data['payment_type']);
72: }
73: if (\array_key_exists('amount', $data)) {
74: $object->setAmount($this->denormalizer->denormalize($data['amount'], 'NxSys\\Library\\Clients\\Brex\\API\\Payments\\Model\\Money', 'json', $context));
75: unset($data['amount']);
76: }
77: if (\array_key_exists('process_date', $data) && $data['process_date'] !== null) {
78: $object->setProcessDate(\DateTime::createFromFormat('Y-m-d', $data['process_date'])->setTime(0, 0, 0));
79: unset($data['process_date']);
80: } elseif (\array_key_exists('process_date', $data) && $data['process_date'] === null) {
81: $object->setProcessDate(null);
82: }
83: if (\array_key_exists('originating_account', $data)) {
84: $values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
85: foreach ($data['originating_account'] as $key => $value) {
86: $values[$key] = $value;
87: }
88: $object->setOriginatingAccount($values);
89: unset($data['originating_account']);
90: }
91: if (\array_key_exists('status', $data)) {
92: $object->setStatus($data['status']);
93: unset($data['status']);
94: }
95: if (\array_key_exists('cancellation_reason', $data)) {
96: $object->setCancellationReason($data['cancellation_reason']);
97: unset($data['cancellation_reason']);
98: }
99: if (\array_key_exists('estimated_delivery_date', $data) && $data['estimated_delivery_date'] !== null) {
100: $object->setEstimatedDeliveryDate(\DateTime::createFromFormat('Y-m-d', $data['estimated_delivery_date'])->setTime(0, 0, 0));
101: unset($data['estimated_delivery_date']);
102: } elseif (\array_key_exists('estimated_delivery_date', $data) && $data['estimated_delivery_date'] === null) {
103: $object->setEstimatedDeliveryDate(null);
104: }
105: if (\array_key_exists('creator_user_id', $data) && $data['creator_user_id'] !== null) {
106: $object->setCreatorUserId($data['creator_user_id']);
107: unset($data['creator_user_id']);
108: } elseif (\array_key_exists('creator_user_id', $data) && $data['creator_user_id'] === null) {
109: $object->setCreatorUserId(null);
110: }
111: if (\array_key_exists('created_at', $data) && $data['created_at'] !== null) {
112: $object->setCreatedAt(\DateTime::createFromFormat('Y-m-d', $data['created_at'])->setTime(0, 0, 0));
113: unset($data['created_at']);
114: } elseif (\array_key_exists('created_at', $data) && $data['created_at'] === null) {
115: $object->setCreatedAt(null);
116: }
117: if (\array_key_exists('display_name', $data) && $data['display_name'] !== null) {
118: $object->setDisplayName($data['display_name']);
119: unset($data['display_name']);
120: } elseif (\array_key_exists('display_name', $data) && $data['display_name'] === null) {
121: $object->setDisplayName(null);
122: }
123: if (\array_key_exists('external_memo', $data) && $data['external_memo'] !== null) {
124: $object->setExternalMemo($data['external_memo']);
125: unset($data['external_memo']);
126: } elseif (\array_key_exists('external_memo', $data) && $data['external_memo'] === null) {
127: $object->setExternalMemo(null);
128: }
129: foreach ($data as $key_1 => $value_1) {
130: if (preg_match('/.*/', (string) $key_1)) {
131: $object[$key_1] = $value_1;
132: }
133: }
134:
135: return $object;
136: }
137:
138: /**
139: * @return array|string|int|float|bool|\ArrayObject|null
140: */
141: public function normalize($object, $format = null, array $context = [])
142: {
143: $data = [];
144: $data['id'] = $object->getId();
145: if ($object->isInitialized('counterparty') && null !== $object->getCounterparty()) {
146: $data['counterparty'] = $this->normalizer->normalize($object->getCounterparty(), 'json', $context);
147: }
148: if ($object->isInitialized('description') && null !== $object->getDescription()) {
149: $data['description'] = $object->getDescription();
150: }
151: $data['payment_type'] = $object->getPaymentType();
152: $data['amount'] = $this->normalizer->normalize($object->getAmount(), 'json', $context);
153: if ($object->isInitialized('processDate') && null !== $object->getProcessDate()) {
154: $data['process_date'] = $object->getProcessDate()->format('Y-m-d');
155: }
156: $values = [];
157: foreach ($object->getOriginatingAccount() as $key => $value) {
158: $values[$key] = $value;
159: }
160: $data['originating_account'] = $values;
161: $data['status'] = $object->getStatus();
162: if ($object->isInitialized('cancellationReason') && null !== $object->getCancellationReason()) {
163: $data['cancellation_reason'] = $object->getCancellationReason();
164: }
165: if ($object->isInitialized('estimatedDeliveryDate') && null !== $object->getEstimatedDeliveryDate()) {
166: $data['estimated_delivery_date'] = $object->getEstimatedDeliveryDate()->format('Y-m-d');
167: }
168: if ($object->isInitialized('creatorUserId') && null !== $object->getCreatorUserId()) {
169: $data['creator_user_id'] = $object->getCreatorUserId();
170: }
171: if ($object->isInitialized('createdAt') && null !== $object->getCreatedAt()) {
172: $data['created_at'] = $object->getCreatedAt()->format('Y-m-d');
173: }
174: if ($object->isInitialized('displayName') && null !== $object->getDisplayName()) {
175: $data['display_name'] = $object->getDisplayName();
176: }
177: if ($object->isInitialized('externalMemo') && null !== $object->getExternalMemo()) {
178: $data['external_memo'] = $object->getExternalMemo();
179: }
180: foreach ($object as $key_1 => $value_1) {
181: if (preg_match('/.*/', (string) $key_1)) {
182: $data[$key_1] = $value_1;
183: }
184: }
185:
186: return $data;
187: }
188: }
189: