/** * @expectedException \InvalidArgumentException */ public function testUncallableCallbacks() { $this->normalizer->setCallbacks(array('bar' => null)); $obj = new GetConstructorDummy('baz', 'quux', true); $this->normalizer->normalize($obj, 'any'); }
/** * Lists all Task entities. * */ public function listAction() { $user = $this->get('security.context')->getToken()->getUser(); $em = $this->getDoctrine()->getManager(); $tasks = $em->getRepository('STMSBundle:Task')->findBy(array('user' => $user)); $normalizer = new GetSetMethodNormalizer(); $normalizer->setIgnoredAttributes(array('user')); $normalizer->setCallbacks(array('date' => function ($dateTime) { return $dateTime->format("Y-m-d"); })); $serializer = new Serializer(array($normalizer), array(new JsonEncoder())); $json = $serializer->serialize($tasks, 'json'); $response = new Response($json); $response->headers->set('Content-Type', 'application/json'); return $response; }
public function benchSymfonyGetSetNormalizer() { $normalizer = new GetSetMethodNormalizer(); $normalizer->setCallbacks(array('createdAt' => function (\DateTime $date) { return $date->format(\DateTime::RFC3339); })); $normalizers = array($normalizer); $encoders = array(new JsonEncoder()); $symfony = new Serializer($normalizers, $encoders); return $symfony->serialize($this->data, 'json'); }