1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
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 ACHDetailsResponseNormalizer 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\\ACHDetailsResponse'; |
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\\ACHDetailsResponse'; |
38: | } |
39: | |
40: | |
41: | |
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\ACHDetailsResponse(); |
52: | if (null === $data || false === \is_array($data)) { |
53: | return $object; |
54: | } |
55: | if (\array_key_exists('type', $data)) { |
56: | $object->setType($data['type']); |
57: | unset($data['type']); |
58: | } |
59: | if (\array_key_exists('payment_instrument_id', $data)) { |
60: | $object->setPaymentInstrumentId($data['payment_instrument_id']); |
61: | unset($data['payment_instrument_id']); |
62: | } |
63: | if (\array_key_exists('routing_number', $data)) { |
64: | $object->setRoutingNumber($data['routing_number']); |
65: | unset($data['routing_number']); |
66: | } |
67: | if (\array_key_exists('account_number', $data)) { |
68: | $object->setAccountNumber($data['account_number']); |
69: | unset($data['account_number']); |
70: | } |
71: | if (\array_key_exists('account_type', $data)) { |
72: | $object->setAccountType($data['account_type']); |
73: | unset($data['account_type']); |
74: | } |
75: | if (\array_key_exists('account_class', $data)) { |
76: | $object->setAccountClass($data['account_class']); |
77: | unset($data['account_class']); |
78: | } |
79: | foreach ($data as $key => $value) { |
80: | if (preg_match('/.*/', (string) $key)) { |
81: | $object[$key] = $value; |
82: | } |
83: | } |
84: | |
85: | return $object; |
86: | } |
87: | |
88: | |
89: | |
90: | |
91: | public function normalize($object, $format = null, array $context = []) |
92: | { |
93: | $data = []; |
94: | $data['type'] = $object->getType(); |
95: | $data['payment_instrument_id'] = $object->getPaymentInstrumentId(); |
96: | $data['routing_number'] = $object->getRoutingNumber(); |
97: | $data['account_number'] = $object->getAccountNumber(); |
98: | if ($object->isInitialized('accountType') && null !== $object->getAccountType()) { |
99: | $data['account_type'] = $object->getAccountType(); |
100: | } |
101: | if ($object->isInitialized('accountClass') && null !== $object->getAccountClass()) { |
102: | $data['account_class'] = $object->getAccountClass(); |
103: | } |
104: | foreach ($object as $key => $value) { |
105: | if (preg_match('/.*/', (string) $key)) { |
106: | $data[$key] = $value; |
107: | } |
108: | } |
109: | |
110: | return $data; |
111: | } |
112: | } |
113: | |