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 CreateIncomingTransferRequestNormalizer 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\\CreateIncomingTransferRequest'; |
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\\CreateIncomingTransferRequest'; |
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\CreateIncomingTransferRequest(); |
52: | if (null === $data || false === \is_array($data)) { |
53: | return $object; |
54: | } |
55: | if (\array_key_exists('counterparty', $data)) { |
56: | $values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS); |
57: | foreach ($data['counterparty'] as $key => $value) { |
58: | $values[$key] = $value; |
59: | } |
60: | $object->setCounterparty($values); |
61: | unset($data['counterparty']); |
62: | } |
63: | if (\array_key_exists('receiving_account', $data)) { |
64: | $values_1 = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS); |
65: | foreach ($data['receiving_account'] as $key_1 => $value_1) { |
66: | $values_1[$key_1] = $value_1; |
67: | } |
68: | $object->setReceivingAccount($values_1); |
69: | unset($data['receiving_account']); |
70: | } |
71: | if (\array_key_exists('amount', $data)) { |
72: | $object->setAmount($this->denormalizer->denormalize($data['amount'], 'NxSys\\Library\\Clients\\Brex\\API\\Payments\\Model\\Money', 'json', $context)); |
73: | unset($data['amount']); |
74: | } |
75: | if (\array_key_exists('description', $data)) { |
76: | $object->setDescription($data['description']); |
77: | unset($data['description']); |
78: | } |
79: | foreach ($data as $key_2 => $value_2) { |
80: | if (preg_match('/.*/', (string) $key_2)) { |
81: | $object[$key_2] = $value_2; |
82: | } |
83: | } |
84: | |
85: | return $object; |
86: | } |
87: | |
88: | |
89: | |
90: | |
91: | public function normalize($object, $format = null, array $context = []) |
92: | { |
93: | $data = []; |
94: | $values = []; |
95: | foreach ($object->getCounterparty() as $key => $value) { |
96: | $values[$key] = $value; |
97: | } |
98: | $data['counterparty'] = $values; |
99: | $values_1 = []; |
100: | foreach ($object->getReceivingAccount() as $key_1 => $value_1) { |
101: | $values_1[$key_1] = $value_1; |
102: | } |
103: | $data['receiving_account'] = $values_1; |
104: | $data['amount'] = $this->normalizer->normalize($object->getAmount(), 'json', $context); |
105: | $data['description'] = $object->getDescription(); |
106: | foreach ($object as $key_2 => $value_2) { |
107: | if (preg_match('/.*/', (string) $key_2)) { |
108: | $data[$key_2] = $value_2; |
109: | } |
110: | } |
111: | |
112: | return $data; |
113: | } |
114: | } |
115: | |