|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of JoliCode's Slack PHP API project. |
| 7 | + * |
| 8 | + * (c) JoliCode <coucou@jolicode.com> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view the LICENSE |
| 11 | + * file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace JoliCode\Slack\Api\Normalizer; |
| 15 | + |
| 16 | +use Jane\Component\JsonSchemaRuntime\Reference; |
| 17 | +use JoliCode\Slack\Api\Runtime\Normalizer\CheckArray; |
| 18 | +use JoliCode\Slack\Api\Runtime\Normalizer\ValidatorTrait; |
| 19 | +use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; |
| 20 | +use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; |
| 21 | +use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
| 22 | +use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; |
| 23 | +use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; |
| 24 | +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
| 25 | + |
| 26 | +class ObjsMetadataNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface |
| 27 | +{ |
| 28 | + use CheckArray; |
| 29 | + use DenormalizerAwareTrait; |
| 30 | + use NormalizerAwareTrait; |
| 31 | + use ValidatorTrait; |
| 32 | + |
| 33 | + public function supportsDenormalization($data, $type, $format = null, array $context = []): bool |
| 34 | + { |
| 35 | + return 'JoliCode\\Slack\\Api\\Model\\ObjsMetadata' === $type; |
| 36 | + } |
| 37 | + |
| 38 | + public function supportsNormalization($data, $format = null, array $context = []): bool |
| 39 | + { |
| 40 | + return \is_object($data) && 'JoliCode\\Slack\\Api\\Model\\ObjsMetadata' === \get_class($data); |
| 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 \JoliCode\Slack\Api\Model\ObjsMetadata(); |
| 52 | + if (null === $data || false === \is_array($data)) { |
| 53 | + return $object; |
| 54 | + } |
| 55 | + if (\array_key_exists('event_payload', $data) && null !== $data['event_payload']) { |
| 56 | + $object->setEventPayload($data['event_payload']); |
| 57 | + } elseif (\array_key_exists('event_payload', $data) && null === $data['event_payload']) { |
| 58 | + $object->setEventPayload(null); |
| 59 | + } |
| 60 | + if (\array_key_exists('event_type', $data) && null !== $data['event_type']) { |
| 61 | + $object->setEventType($data['event_type']); |
| 62 | + } elseif (\array_key_exists('event_type', $data) && null === $data['event_type']) { |
| 63 | + $object->setEventType(null); |
| 64 | + } |
| 65 | + |
| 66 | + return $object; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @return array|string|int|float|bool|\ArrayObject|null |
| 71 | + */ |
| 72 | + public function normalize($object, $format = null, array $context = []) |
| 73 | + { |
| 74 | + $data = []; |
| 75 | + $data['event_payload'] = $object->getEventPayload(); |
| 76 | + $data['event_type'] = $object->getEventType(); |
| 77 | + |
| 78 | + return $data; |
| 79 | + } |
| 80 | + |
| 81 | + public function getSupportedTypes(string $format = null): array |
| 82 | + { |
| 83 | + return ['JoliCode\\Slack\\Api\\Model\\ObjsMetadata' => false]; |
| 84 | + } |
| 85 | +} |
0 commit comments