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 BeneficiaryBankNormalizer 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\\BeneficiaryBank'; |
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\\BeneficiaryBank'; |
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\BeneficiaryBank(); |
52: | if (null === $data || false === \is_array($data)) { |
53: | return $object; |
54: | } |
55: | if (\array_key_exists('name', $data) && $data['name'] !== null) { |
56: | $object->setName($data['name']); |
57: | unset($data['name']); |
58: | } elseif (\array_key_exists('name', $data) && $data['name'] === null) { |
59: | $object->setName(null); |
60: | } |
61: | if (\array_key_exists('address', $data)) { |
62: | $object->setAddress($this->denormalizer->denormalize($data['address'], 'NxSys\\Library\\Clients\\Brex\\API\\Payments\\Model\\BeneficiaryBankAddress', 'json', $context)); |
63: | unset($data['address']); |
64: | } |
65: | foreach ($data as $key => $value) { |
66: | if (preg_match('/.*/', (string) $key)) { |
67: | $object[$key] = $value; |
68: | } |
69: | } |
70: | |
71: | return $object; |
72: | } |
73: | |
74: | |
75: | |
76: | |
77: | public function normalize($object, $format = null, array $context = []) |
78: | { |
79: | $data = []; |
80: | if ($object->isInitialized('name') && null !== $object->getName()) { |
81: | $data['name'] = $object->getName(); |
82: | } |
83: | if ($object->isInitialized('address') && null !== $object->getAddress()) { |
84: | $data['address'] = $this->normalizer->normalize($object->getAddress(), 'json', $context); |
85: | } |
86: | foreach ($object as $key => $value) { |
87: | if (preg_match('/.*/', (string) $key)) { |
88: | $data[$key] = $value; |
89: | } |
90: | } |
91: | |
92: | return $data; |
93: | } |
94: | } |
95: | |