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 BankConnectionNormalizer 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\\BankConnection';
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\\BankConnection';
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\BankConnection();
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('bank_details', $data)) {
60: $object->setBankDetails($this->denormalizer->denormalize($data['bank_details'], 'NxSys\\Library\\Clients\\Brex\\API\\Payments\\Model\\BankDetails', 'json', $context));
61: unset($data['bank_details']);
62: }
63: if (\array_key_exists('brex_account_id', $data) && $data['brex_account_id'] !== null) {
64: $object->setBrexAccountId($data['brex_account_id']);
65: unset($data['brex_account_id']);
66: } elseif (\array_key_exists('brex_account_id', $data) && $data['brex_account_id'] === null) {
67: $object->setBrexAccountId(null);
68: }
69: if (\array_key_exists('last_four', $data)) {
70: $object->setLastFour($data['last_four']);
71: unset($data['last_four']);
72: }
73: if (\array_key_exists('available_balance', $data)) {
74: $object->setAvailableBalance($this->denormalizer->denormalize($data['available_balance'], 'NxSys\\Library\\Clients\\Brex\\API\\Payments\\Model\\BankConnectionAvailableBalance', 'json', $context));
75: unset($data['available_balance']);
76: }
77: if (\array_key_exists('current_balance', $data)) {
78: $object->setCurrentBalance($this->denormalizer->denormalize($data['current_balance'], 'NxSys\\Library\\Clients\\Brex\\API\\Payments\\Model\\BankConnectionCurrentBalance', 'json', $context));
79: unset($data['current_balance']);
80: }
81: foreach ($data as $key => $value) {
82: if (preg_match('/.*/', (string) $key)) {
83: $object[$key] = $value;
84: }
85: }
86:
87: return $object;
88: }
89:
90: /**
91: * @return array|string|int|float|bool|\ArrayObject|null
92: */
93: public function normalize($object, $format = null, array $context = [])
94: {
95: $data = [];
96: $data['id'] = $object->getId();
97: if ($object->isInitialized('bankDetails') && null !== $object->getBankDetails()) {
98: $data['bank_details'] = $this->normalizer->normalize($object->getBankDetails(), 'json', $context);
99: }
100: if ($object->isInitialized('brexAccountId') && null !== $object->getBrexAccountId()) {
101: $data['brex_account_id'] = $object->getBrexAccountId();
102: }
103: $data['last_four'] = $object->getLastFour();
104: if ($object->isInitialized('availableBalance') && null !== $object->getAvailableBalance()) {
105: $data['available_balance'] = $this->normalizer->normalize($object->getAvailableBalance(), 'json', $context);
106: }
107: if ($object->isInitialized('currentBalance') && null !== $object->getCurrentBalance()) {
108: $data['current_balance'] = $this->normalizer->normalize($object->getCurrentBalance(), 'json', $context);
109: }
110: foreach ($object as $key => $value) {
111: if (preg_match('/.*/', (string) $key)) {
112: $data[$key] = $value;
113: }
114: }
115:
116: return $data;
117: }
118: }
119: