Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppBundle\Service;
- use Symfony\Component\Serializer\Encoder\JsonEncoder;
- use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
- use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
- use Symfony\Component\Serializer\Serializer;
- class SerializerService
- {
- private $encoders = null;
- private $normalizers = null;
- private $serializer = null;
- /**
- * SerializerService constructor.
- */
- public function __construct()
- {
- $this->encoders = [new JsonEncoder()];
- $this->normalizers = [new DateTimeNormalizer('Y-m-d H:i:s'), new ObjectNormalizer()];
- $this->serializer = new Serializer($this->normalizers, $this->encoders);
- }
- /**
- * @return Serializer
- */
- public function getSerializer(): Serializer
- {
- return $this->serializer;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement