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 CreateCardRequestNormalizer 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\\CreateCardRequest';
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\\CreateCardRequest';
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\CreateCardRequest();
52: if (null === $data || false === \is_array($data)) {
53: return $object;
54: }
55: if (\array_key_exists('owner', $data)) {
56: $values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
57: foreach ($data['owner'] as $key => $value) {
58: $values[$key] = $value;
59: }
60: $object->setOwner($values);
61: unset($data['owner']);
62: }
63: if (\array_key_exists('card_name', $data)) {
64: $object->setCardName($data['card_name']);
65: unset($data['card_name']);
66: }
67: if (\array_key_exists('card_type', $data)) {
68: $object->setCardType($data['card_type']);
69: unset($data['card_type']);
70: }
71: if (\array_key_exists('limit_type', $data)) {
72: $object->setLimitType($data['limit_type']);
73: unset($data['limit_type']);
74: }
75: if (\array_key_exists('spend_controls', $data)) {
76: $object->setSpendControls($this->denormalizer->denormalize($data['spend_controls'], 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\CreateCardRequestSpendControls', 'json', $context));
77: unset($data['spend_controls']);
78: }
79: if (\array_key_exists('mailing_address', $data)) {
80: $object->setMailingAddress($this->denormalizer->denormalize($data['mailing_address'], 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\CreateCardRequestMailingAddress', 'json', $context));
81: unset($data['mailing_address']);
82: }
83: if (\array_key_exists('metadata', $data) && $data['metadata'] !== null) {
84: $values_1 = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
85: foreach ($data['metadata'] as $key_1 => $value_1) {
86: $values_1[$key_1] = $value_1;
87: }
88: $object->setMetadata($values_1);
89: unset($data['metadata']);
90: } elseif (\array_key_exists('metadata', $data) && $data['metadata'] === null) {
91: $object->setMetadata(null);
92: }
93: if (\array_key_exists('card_attribute_preferences', $data)) {
94: $object->setCardAttributePreferences($this->denormalizer->denormalize($data['card_attribute_preferences'], 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\CreateCardRequestCardAttributePreferences', 'json', $context));
95: unset($data['card_attribute_preferences']);
96: }
97: foreach ($data as $key_2 => $value_2) {
98: if (preg_match('/.*/', (string) $key_2)) {
99: $object[$key_2] = $value_2;
100: }
101: }
102:
103: return $object;
104: }
105:
106: /**
107: * @return array|string|int|float|bool|\ArrayObject|null
108: */
109: public function normalize($object, $format = null, array $context = [])
110: {
111: $data = [];
112: $values = [];
113: foreach ($object->getOwner() as $key => $value) {
114: $values[$key] = $value;
115: }
116: $data['owner'] = $values;
117: $data['card_name'] = $object->getCardName();
118: $data['card_type'] = $object->getCardType();
119: $data['limit_type'] = $object->getLimitType();
120: if ($object->isInitialized('spendControls') && null !== $object->getSpendControls()) {
121: $data['spend_controls'] = $this->normalizer->normalize($object->getSpendControls(), 'json', $context);
122: }
123: if ($object->isInitialized('mailingAddress') && null !== $object->getMailingAddress()) {
124: $data['mailing_address'] = $this->normalizer->normalize($object->getMailingAddress(), 'json', $context);
125: }
126: if ($object->isInitialized('metadata') && null !== $object->getMetadata()) {
127: $values_1 = [];
128: foreach ($object->getMetadata() as $key_1 => $value_1) {
129: $values_1[$key_1] = $value_1;
130: }
131: $data['metadata'] = $values_1;
132: }
133: if ($object->isInitialized('cardAttributePreferences') && null !== $object->getCardAttributePreferences()) {
134: $data['card_attribute_preferences'] = $this->normalizer->normalize($object->getCardAttributePreferences(), 'json', $context);
135: }
136: foreach ($object as $key_2 => $value_2) {
137: if (preg_match('/.*/', (string) $key_2)) {
138: $data[$key_2] = $value_2;
139: }
140: }
141:
142: return $data;
143: }
144: }
145: