Skip to content

Instantly share code, notes, and snippets.

@greenplugin
Created February 26, 2020 12:23
Show Gist options
  • Save greenplugin/aeffb9c6c10003bf18a3e0ef38ccb0d9 to your computer and use it in GitHub Desktop.
Save greenplugin/aeffb9c6c10003bf18a3e0ef38ccb0d9 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace TgBotApi\BotApiBase\Normalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use TgBotApi\BotApiBase\Method\SendPollMethod;
use Symfony\Component\Serializer\Serializer;
class SendPoollNormalizer implements NormalizerInterface
{
/**
* @var NormalizerInterface
*/
private $objectNormalizer;
/**
* JsonSerializableNormalizer constructor.
*
* @param NormalizerInterface $objectNormalizer
*/
public function __construct(NormalizerInterface $objectNormalizer)
{
$this->objectNormalizer = $objectNormalizer;
}
/**
* @param mixed $topic
* @param null $format
* @param array $context
*
* @throws ExceptionInterface
*
* @return array|bool|false|float|int|string
*/
public function normalize($topic, $format = null, array $context = [])
{
$serializer = new Serializer([$this->objectNormalizer]);
$topic->options = \json_encode($topic->options);
return $serializer->normalize($topic, null, ['skip_null_values' => true]);
}
/**
* @param mixed $data
* @param null $format
*
* @return bool
*/
public function supportsNormalization($data, $format = null): bool
{
return $data instanceof SendPollMethod;
}
}
@anh1200a
Copy link

Oke

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment