| @@ 24-63 (lines=40) @@ | ||
| 21 | use Symfony\Component\Serializer\NameConverter\NameConverterInterface; |
|
| 22 | use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
|
| 23 | ||
| 24 | final class SymfonyNotificationMarkedAsReadDenormalizer implements DenormalizerInterface |
|
| 25 | { |
|
| 26 | private $nameConverter; |
|
| 27 | ||
| 28 | public function __construct(NameConverterInterface $nameConverter) |
|
| 29 | { |
|
| 30 | $this->nameConverter = $nameConverter; |
|
| 31 | } |
|
| 32 | ||
| 33 | public function denormalize($data, $class, $format = null, array $context = []) : NotificationMarkedAsRead |
|
| 34 | { |
|
| 35 | $notificationMarkedAsRead = new NotificationMarkedAsRead( |
|
| 36 | NotificationId::generate($data['payload']['id']), |
|
| 37 | UserId::generate($data['payload']['user_id']) |
|
| 38 | ); |
|
| 39 | ||
| 40 | $reflectionClass = new \ReflectionClass($notificationMarkedAsRead); |
|
| 41 | $reflectionProperty = $reflectionClass->getProperty('occurredOn'); |
|
| 42 | $reflectionProperty->setAccessible(true); |
|
| 43 | $reflectionProperty->setValue( |
|
| 44 | $notificationMarkedAsRead, |
|
| 45 | \DateTimeImmutable::createFromFormat('U', (string) $data['occurred_on']) |
|
| 46 | ); |
|
| 47 | ||
| 48 | $reflectionProperty = $reflectionClass->getProperty('status'); |
|
| 49 | $reflectionProperty->setAccessible(true); |
|
| 50 | $reflectionProperty->setValue( |
|
| 51 | $notificationMarkedAsRead, |
|
| 52 | new NotificationStatus($data['payload']['status']) |
|
| 53 | ); |
|
| 54 | ||
| 55 | return $notificationMarkedAsRead; |
|
| 56 | } |
|
| 57 | ||
| 58 | public function supportsDenormalization($data, $type, $format = null) : bool |
|
| 59 | { |
|
| 60 | return isset($data['type']) |
|
| 61 | && $this->nameConverter->denormalize($data['type']) === NotificationMarkedAsRead::class; |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||
| @@ 24-63 (lines=40) @@ | ||
| 21 | use Symfony\Component\Serializer\NameConverter\NameConverterInterface; |
|
| 22 | use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
|
| 23 | ||
| 24 | final class SymfonyNotificationMarkedAsUnreadDenormalizer implements DenormalizerInterface |
|
| 25 | { |
|
| 26 | private $nameConverter; |
|
| 27 | ||
| 28 | public function __construct(NameConverterInterface $nameConverter) |
|
| 29 | { |
|
| 30 | $this->nameConverter = $nameConverter; |
|
| 31 | } |
|
| 32 | ||
| 33 | public function denormalize($data, $class, $format = null, array $context = []) : NotificationMarkedAsUnread |
|
| 34 | { |
|
| 35 | $notificationMarkedAsUnread = new NotificationMarkedAsUnread( |
|
| 36 | NotificationId::generate($data['payload']['id']), |
|
| 37 | UserId::generate($data['payload']['user_id']) |
|
| 38 | ); |
|
| 39 | ||
| 40 | $reflectionClass = new \ReflectionClass($notificationMarkedAsUnread); |
|
| 41 | $reflectionProperty = $reflectionClass->getProperty('occurredOn'); |
|
| 42 | $reflectionProperty->setAccessible(true); |
|
| 43 | $reflectionProperty->setValue( |
|
| 44 | $notificationMarkedAsUnread, |
|
| 45 | \DateTimeImmutable::createFromFormat('U', (string) $data['occurred_on']) |
|
| 46 | ); |
|
| 47 | ||
| 48 | $reflectionProperty = $reflectionClass->getProperty('status'); |
|
| 49 | $reflectionProperty->setAccessible(true); |
|
| 50 | $reflectionProperty->setValue( |
|
| 51 | $notificationMarkedAsUnread, |
|
| 52 | new NotificationStatus($data['payload']['status']) |
|
| 53 | ); |
|
| 54 | ||
| 55 | return $notificationMarkedAsUnread; |
|
| 56 | } |
|
| 57 | ||
| 58 | public function supportsDenormalization($data, $type, $format = null) : bool |
|
| 59 | { |
|
| 60 | return isset($data['type']) |
|
| 61 | && $this->nameConverter->denormalize($data['type']) === NotificationMarkedAsUnread::class; |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||