1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | namespace NxSys\Library\Clients\Brex\API\Team\Normalizer; |
12: | |
13: | use Jane\Component\JsonSchemaRuntime\Reference; |
14: | use NxSys\Library\Clients\Brex\API\Team\Runtime\Normalizer\CheckArray; |
15: | use NxSys\Library\Clients\Brex\API\Team\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 SecureEmailForCardDetailsRequestNormalizer 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\\Team\\Model\\SecureEmailForCardDetailsRequest'; |
33: | } |
34: | |
35: | public function supportsNormalization($data, $format = null): bool |
36: | { |
37: | return is_object($data) && get_class($data) === 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\SecureEmailForCardDetailsRequest'; |
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\Team\Model\SecureEmailForCardDetailsRequest(); |
52: | if (null === $data || false === \is_array($data)) { |
53: | return $object; |
54: | } |
55: | if (\array_key_exists('recipient_email', $data)) { |
56: | $object->setRecipientEmail($data['recipient_email']); |
57: | unset($data['recipient_email']); |
58: | } |
59: | if (\array_key_exists('sender_name', $data)) { |
60: | $object->setSenderName($data['sender_name']); |
61: | unset($data['sender_name']); |
62: | } |
63: | if (\array_key_exists('message', $data) && $data['message'] !== null) { |
64: | $object->setMessage($data['message']); |
65: | unset($data['message']); |
66: | } elseif (\array_key_exists('message', $data) && $data['message'] === null) { |
67: | $object->setMessage(null); |
68: | } |
69: | if (\array_key_exists('expiry_days', $data) && $data['expiry_days'] !== null) { |
70: | $object->setExpiryDays($data['expiry_days']); |
71: | unset($data['expiry_days']); |
72: | } elseif (\array_key_exists('expiry_days', $data) && $data['expiry_days'] === null) { |
73: | $object->setExpiryDays(null); |
74: | } |
75: | foreach ($data as $key => $value) { |
76: | if (preg_match('/.*/', (string) $key)) { |
77: | $object[$key] = $value; |
78: | } |
79: | } |
80: | |
81: | return $object; |
82: | } |
83: | |
84: | |
85: | |
86: | |
87: | public function normalize($object, $format = null, array $context = []) |
88: | { |
89: | $data = []; |
90: | if ($object->isInitialized('recipientEmail') && null !== $object->getRecipientEmail()) { |
91: | $data['recipient_email'] = $object->getRecipientEmail(); |
92: | } |
93: | if ($object->isInitialized('senderName') && null !== $object->getSenderName()) { |
94: | $data['sender_name'] = $object->getSenderName(); |
95: | } |
96: | if ($object->isInitialized('message') && null !== $object->getMessage()) { |
97: | $data['message'] = $object->getMessage(); |
98: | } |
99: | if ($object->isInitialized('expiryDays') && null !== $object->getExpiryDays()) { |
100: | $data['expiry_days'] = $object->getExpiryDays(); |
101: | } |
102: | foreach ($object as $key => $value) { |
103: | if (preg_match('/.*/', (string) $key)) { |
104: | $data[$key] = $value; |
105: | } |
106: | } |
107: | |
108: | return $data; |
109: | } |
110: | } |
111: | |