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 UpdateVendorRequestNormalizer 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\\UpdateVendorRequest'; |
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\\UpdateVendorRequest'; |
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\UpdateVendorRequest(); |
52: | if (null === $data || false === \is_array($data)) { |
53: | return $object; |
54: | } |
55: | if (\array_key_exists('company_name', $data) && $data['company_name'] !== null) { |
56: | $object->setCompanyName($data['company_name']); |
57: | unset($data['company_name']); |
58: | } elseif (\array_key_exists('company_name', $data) && $data['company_name'] === null) { |
59: | $object->setCompanyName(null); |
60: | } |
61: | if (\array_key_exists('email', $data) && $data['email'] !== null) { |
62: | $object->setEmail($data['email']); |
63: | unset($data['email']); |
64: | } elseif (\array_key_exists('email', $data) && $data['email'] === null) { |
65: | $object->setEmail(null); |
66: | } |
67: | if (\array_key_exists('phone', $data) && $data['phone'] !== null) { |
68: | $object->setPhone($data['phone']); |
69: | unset($data['phone']); |
70: | } elseif (\array_key_exists('phone', $data) && $data['phone'] === null) { |
71: | $object->setPhone(null); |
72: | } |
73: | if (\array_key_exists('payment_accounts', $data) && $data['payment_accounts'] !== null) { |
74: | $values = []; |
75: | foreach ($data['payment_accounts'] as $value) { |
76: | $values[] = $this->denormalizer->denormalize($value, 'NxSys\\Library\\Clients\\Brex\\API\\Payments\\Model\\PaymentAccountRequest', 'json', $context); |
77: | } |
78: | $object->setPaymentAccounts($values); |
79: | unset($data['payment_accounts']); |
80: | } elseif (\array_key_exists('payment_accounts', $data) && $data['payment_accounts'] === null) { |
81: | $object->setPaymentAccounts(null); |
82: | } |
83: | foreach ($data as $key => $value_1) { |
84: | if (preg_match('/.*/', (string) $key)) { |
85: | $object[$key] = $value_1; |
86: | } |
87: | } |
88: | |
89: | return $object; |
90: | } |
91: | |
92: | |
93: | |
94: | |
95: | public function normalize($object, $format = null, array $context = []) |
96: | { |
97: | $data = []; |
98: | if ($object->isInitialized('companyName') && null !== $object->getCompanyName()) { |
99: | $data['company_name'] = $object->getCompanyName(); |
100: | } |
101: | if ($object->isInitialized('email') && null !== $object->getEmail()) { |
102: | $data['email'] = $object->getEmail(); |
103: | } |
104: | if ($object->isInitialized('phone') && null !== $object->getPhone()) { |
105: | $data['phone'] = $object->getPhone(); |
106: | } |
107: | if ($object->isInitialized('paymentAccounts') && null !== $object->getPaymentAccounts()) { |
108: | $values = []; |
109: | foreach ($object->getPaymentAccounts() as $value) { |
110: | $values[] = $this->normalizer->normalize($value, 'json', $context); |
111: | } |
112: | $data['payment_accounts'] = $values; |
113: | } |
114: | foreach ($object as $key => $value_1) { |
115: | if (preg_match('/.*/', (string) $key)) { |
116: | $data[$key] = $value_1; |
117: | } |
118: | } |
119: | |
120: | return $data; |
121: | } |
122: | } |
123: | |