1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | namespace NxSys\Library\Clients\Brex\API\Webhooks\Normalizer; |
12: | |
13: | use Jane\Component\JsonSchemaRuntime\Reference; |
14: | use NxSys\Library\Clients\Brex\API\Webhooks\Runtime\Normalizer\CheckArray; |
15: | use NxSys\Library\Clients\Brex\API\Webhooks\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 TransferProcessedEventNormalizer 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\\Webhooks\\Model\\TransferProcessedEvent'; |
33: | } |
34: | |
35: | public function supportsNormalization($data, $format = null): bool |
36: | { |
37: | return is_object($data) && get_class($data) === 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\TransferProcessedEvent'; |
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\Webhooks\Model\TransferProcessedEvent(); |
52: | if (null === $data || false === \is_array($data)) { |
53: | return $object; |
54: | } |
55: | if (\array_key_exists('event_type', $data)) { |
56: | $object->setEventType($data['event_type']); |
57: | unset($data['event_type']); |
58: | } |
59: | if (\array_key_exists('transfer_id', $data)) { |
60: | $object->setTransferId($data['transfer_id']); |
61: | unset($data['transfer_id']); |
62: | } |
63: | if (\array_key_exists('payment_type', $data)) { |
64: | $object->setPaymentType($data['payment_type']); |
65: | unset($data['payment_type']); |
66: | } |
67: | if (\array_key_exists('return_for_id', $data) && $data['return_for_id'] !== null) { |
68: | $object->setReturnForId($data['return_for_id']); |
69: | unset($data['return_for_id']); |
70: | } elseif (\array_key_exists('return_for_id', $data) && $data['return_for_id'] === null) { |
71: | $object->setReturnForId(null); |
72: | } |
73: | if (\array_key_exists('company_id', $data)) { |
74: | $object->setCompanyId($data['company_id']); |
75: | unset($data['company_id']); |
76: | } |
77: | foreach ($data as $key => $value) { |
78: | if (preg_match('/.*/', (string) $key)) { |
79: | $object[$key] = $value; |
80: | } |
81: | } |
82: | |
83: | return $object; |
84: | } |
85: | |
86: | |
87: | |
88: | |
89: | public function normalize($object, $format = null, array $context = []) |
90: | { |
91: | $data = []; |
92: | $data['event_type'] = $object->getEventType(); |
93: | $data['transfer_id'] = $object->getTransferId(); |
94: | $data['payment_type'] = $object->getPaymentType(); |
95: | if ($object->isInitialized('returnForId') && null !== $object->getReturnForId()) { |
96: | $data['return_for_id'] = $object->getReturnForId(); |
97: | } |
98: | if ($object->isInitialized('companyId') && null !== $object->getCompanyId()) { |
99: | $data['company_id'] = $object->getCompanyId(); |
100: | } |
101: | foreach ($object as $key => $value) { |
102: | if (preg_match('/.*/', (string) $key)) { |
103: | $data[$key] = $value; |
104: | } |
105: | } |
106: | |
107: | return $data; |
108: | } |
109: | } |
110: | |