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 NxSys\Library\Clients\Brex\API\Webhooks\Runtime\Normalizer\CheckArray; |
14: | use NxSys\Library\Clients\Brex\API\Webhooks\Runtime\Normalizer\ValidatorTrait; |
15: | use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; |
16: | use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; |
17: | use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
18: | use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; |
19: | use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; |
20: | use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
21: | |
22: | class JaneObjectNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface |
23: | { |
24: | use DenormalizerAwareTrait; |
25: | use NormalizerAwareTrait; |
26: | use CheckArray; |
27: | use ValidatorTrait; |
28: | protected $normalizers = ['NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\CreateWebhookSubscriptionRequest' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\CreateWebhookSubscriptionRequestNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\ExpensePaymentStatusUpdatedEvent' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\ExpensePaymentStatusUpdatedEventNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\ExpensePaymentStatusUpdatedEventAmount' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\ExpensePaymentStatusUpdatedEventAmountNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\Money' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\MoneyNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\PageWebhookSubscription' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\PageWebhookSubscriptionNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\ProductApplication' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\ProductApplicationNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\ReferralActivatedEvent' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\ReferralActivatedEventNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\ReferralApplicationStatusChangedEvent' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\ReferralApplicationStatusChangedEventNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\ReferralCreatedEvent' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\ReferralCreatedEventNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\TransferEvent' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\TransferEventNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\TransferFailedEvent' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\TransferFailedEventNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\TransferProcessedEvent' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\TransferProcessedEventNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\UpdateWebhookSubscriptionRequest' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\UpdateWebhookSubscriptionRequestNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\UserUpdatedEvent' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\UserUpdatedEventNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\WebhookSecret' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\WebhookSecretNormalizer', 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Model\\WebhookSubscription' => 'NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Normalizer\\WebhookSubscriptionNormalizer', '\\Jane\\Component\\JsonSchemaRuntime\\Reference' => '\\NxSys\\Library\\Clients\\Brex\\API\\Webhooks\\Runtime\\Normalizer\\ReferenceNormalizer']; |
29: | protected $normalizersCache = []; |
30: | |
31: | public function supportsDenormalization($data, $type, $format = null): bool |
32: | { |
33: | return array_key_exists($type, $this->normalizers); |
34: | } |
35: | |
36: | public function supportsNormalization($data, $format = null): bool |
37: | { |
38: | return is_object($data) && array_key_exists(get_class($data), $this->normalizers); |
39: | } |
40: | |
41: | |
42: | |
43: | |
44: | public function normalize($object, $format = null, array $context = []) |
45: | { |
46: | $normalizerClass = $this->normalizers[get_class($object)]; |
47: | $normalizer = $this->getNormalizer($normalizerClass); |
48: | |
49: | return $normalizer->normalize($object, $format, $context); |
50: | } |
51: | |
52: | |
53: | |
54: | |
55: | public function denormalize($data, $class, $format = null, array $context = []) |
56: | { |
57: | $denormalizerClass = $this->normalizers[$class]; |
58: | $denormalizer = $this->getNormalizer($denormalizerClass); |
59: | |
60: | return $denormalizer->denormalize($data, $class, $format, $context); |
61: | } |
62: | |
63: | private function getNormalizer(string $normalizerClass) |
64: | { |
65: | return $this->normalizersCache[$normalizerClass] ?? $this->initNormalizer($normalizerClass); |
66: | } |
67: | |
68: | private function initNormalizer(string $normalizerClass) |
69: | { |
70: | $normalizer = new $normalizerClass(); |
71: | $normalizer->setNormalizer($this->normalizer); |
72: | $normalizer->setDenormalizer($this->denormalizer); |
73: | $this->normalizersCache[$normalizerClass] = $normalizer; |
74: | |
75: | return $normalizer; |
76: | } |
77: | } |
78: | |