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\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 CardNormalizer 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\\Card';
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\\Card';
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\Team\Model\Card();
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('owner', $data)) {
60: $values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
61: foreach ($data['owner'] as $key => $value) {
62: $values[$key] = $value;
63: }
64: $object->setOwner($values);
65: unset($data['owner']);
66: }
67: if (\array_key_exists('status', $data)) {
68: $object->setStatus($data['status']);
69: unset($data['status']);
70: }
71: if (\array_key_exists('last_four', $data)) {
72: $object->setLastFour($data['last_four']);
73: unset($data['last_four']);
74: }
75: if (\array_key_exists('card_name', $data)) {
76: $object->setCardName($data['card_name']);
77: unset($data['card_name']);
78: }
79: if (\array_key_exists('card_type', $data)) {
80: $object->setCardType($data['card_type']);
81: unset($data['card_type']);
82: }
83: if (\array_key_exists('limit_type', $data)) {
84: $object->setLimitType($data['limit_type']);
85: unset($data['limit_type']);
86: }
87: if (\array_key_exists('spend_controls', $data)) {
88: $object->setSpendControls($this->denormalizer->denormalize($data['spend_controls'], 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\CardSpendControls', 'json', $context));
89: unset($data['spend_controls']);
90: }
91: if (\array_key_exists('billing_address', $data)) {
92: $object->setBillingAddress($this->denormalizer->denormalize($data['billing_address'], 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\Address', 'json', $context));
93: unset($data['billing_address']);
94: }
95: if (\array_key_exists('mailing_address', $data)) {
96: $object->setMailingAddress($this->denormalizer->denormalize($data['mailing_address'], 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\CardMailingAddress', 'json', $context));
97: unset($data['mailing_address']);
98: }
99: if (\array_key_exists('metadata', $data) && $data['metadata'] !== null) {
100: $values_1 = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
101: foreach ($data['metadata'] as $key_1 => $value_1) {
102: $values_1[$key_1] = $value_1;
103: }
104: $object->setMetadata($values_1);
105: unset($data['metadata']);
106: } elseif (\array_key_exists('metadata', $data) && $data['metadata'] === null) {
107: $object->setMetadata(null);
108: }
109: foreach ($data as $key_2 => $value_2) {
110: if (preg_match('/.*/', (string) $key_2)) {
111: $object[$key_2] = $value_2;
112: }
113: }
114:
115: return $object;
116: }
117:
118: /**
119: * @return array|string|int|float|bool|\ArrayObject|null
120: */
121: public function normalize($object, $format = null, array $context = [])
122: {
123: $data = [];
124: $data['id'] = $object->getId();
125: $values = [];
126: foreach ($object->getOwner() as $key => $value) {
127: $values[$key] = $value;
128: }
129: $data['owner'] = $values;
130: if ($object->isInitialized('status') && null !== $object->getStatus()) {
131: $data['status'] = $object->getStatus();
132: }
133: $data['last_four'] = $object->getLastFour();
134: $data['card_name'] = $object->getCardName();
135: if ($object->isInitialized('cardType') && null !== $object->getCardType()) {
136: $data['card_type'] = $object->getCardType();
137: }
138: $data['limit_type'] = $object->getLimitType();
139: if ($object->isInitialized('spendControls') && null !== $object->getSpendControls()) {
140: $data['spend_controls'] = $this->normalizer->normalize($object->getSpendControls(), 'json', $context);
141: }
142: $data['billing_address'] = $this->normalizer->normalize($object->getBillingAddress(), 'json', $context);
143: if ($object->isInitialized('mailingAddress') && null !== $object->getMailingAddress()) {
144: $data['mailing_address'] = $this->normalizer->normalize($object->getMailingAddress(), 'json', $context);
145: }
146: if ($object->isInitialized('metadata') && null !== $object->getMetadata()) {
147: $values_1 = [];
148: foreach ($object->getMetadata() as $key_1 => $value_1) {
149: $values_1[$key_1] = $value_1;
150: }
151: $data['metadata'] = $values_1;
152: }
153: foreach ($object as $key_2 => $value_2) {
154: if (preg_match('/.*/', (string) $key_2)) {
155: $data[$key_2] = $value_2;
156: }
157: }
158:
159: return $data;
160: }
161: }
162: