Created
February 26, 2020 12:23
-
-
Save greenplugin/aeffb9c6c10003bf18a3e0ef38ccb0d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oke