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 WebhookSubscriptionNormalizer 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\\WebhookSubscription'; |
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\\WebhookSubscription'; |
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\WebhookSubscription(); |
52: | if (null === $data || false === \is_array($data)) { |
53: | return $object; |
54: | } |
55: | if (\array_key_exists('id', $data)) { |
56: | $object->setId($data['id']); |
57: | unset($data['id']); |
58: | } |
59: | if (\array_key_exists('url', $data)) { |
60: | $object->setUrl($data['url']); |
61: | unset($data['url']); |
62: | } |
63: | if (\array_key_exists('event_types', $data)) { |
64: | $values = []; |
65: | foreach ($data['event_types'] as $value) { |
66: | $values[] = $value; |
67: | } |
68: | $object->setEventTypes($values); |
69: | unset($data['event_types']); |
70: | } |
71: | if (\array_key_exists('status', $data)) { |
72: | $object->setStatus($data['status']); |
73: | unset($data['status']); |
74: | } |
75: | foreach ($data as $key => $value_1) { |
76: | if (preg_match('/.*/', (string) $key)) { |
77: | $object[$key] = $value_1; |
78: | } |
79: | } |
80: | |
81: | return $object; |
82: | } |
83: | |
84: | |
85: | |
86: | |
87: | public function normalize($object, $format = null, array $context = []) |
88: | { |
89: | $data = []; |
90: | $data['id'] = $object->getId(); |
91: | $data['url'] = $object->getUrl(); |
92: | $values = []; |
93: | foreach ($object->getEventTypes() as $value) { |
94: | $values[] = $value; |
95: | } |
96: | $data['event_types'] = $values; |
97: | $data['status'] = $object->getStatus(); |
98: | foreach ($object as $key => $value_1) { |
99: | if (preg_match('/.*/', (string) $key)) { |
100: | $data[$key] = $value_1; |
101: | } |
102: | } |
103: | |
104: | return $data; |
105: | } |
106: | } |
107: | |