Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundle\Service;
  4.  
  5. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  6. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  7. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  8. use Symfony\Component\Serializer\Serializer;
  9.  
  10. class SerializerService
  11. {
  12.     private $encoders = null;
  13.     private $normalizers = null;
  14.     private $serializer = null;
  15.  
  16.     /**
  17.      * SerializerService constructor.
  18.      */
  19.     public function __construct()
  20.     {
  21.         $this->encoders = [new JsonEncoder()];
  22.         $this->normalizers = [new DateTimeNormalizer('Y-m-d H:i:s'), new ObjectNormalizer()];
  23.  
  24.         $this->serializer = new Serializer($this->normalizers, $this->encoders);
  25.     }
  26.  
  27.     /**
  28.      * @return Serializer
  29.      */
  30.     public function getSerializer(): Serializer
  31.     {
  32.         return $this->serializer;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement