public function testIgnoredAttributesDenormalize()
 {
     $this->normalizer->setIgnoredAttributes(array('fooBar', 'bar', 'baz'));
     $obj = new ObjectDummy();
     $obj->setFoo('foo');
     $this->assertEquals($obj, $this->normalizer->denormalize(array('fooBar' => 'fooBar', 'foo' => 'foo', 'baz' => 'baz'), __NAMESPACE__ . '\\ObjectDummy'));
 }
 public function testIgnoredAttributes()
 {
     $this->normalizer->setIgnoredAttributes(array('foo', 'bar', 'baz', 'camelCase', 'object'));
     $obj = new ObjectDummy();
     $obj->setFoo('foo');
     $obj->bar = 'bar';
     $obj->setBaz(true);
     $this->assertEquals(array('fooBar' => 'foobar'), $this->normalizer->normalize($obj, 'any'));
 }
Ejemplo n.º 3
0
 public function indexAction()
 {
     $encoders = array(new XmlEncoder(), new JsonEncoder());
     $normalizer = new ObjectNormalizer();
     $normalizer->setIgnoredAttributes(array('username', 'password', 'salt', 'userRoles', 'roles', 'sobiratel', 'informator', 'userid', 'id', 'lazyPropertiesDefaults', '__initializer__', '__cloner__', '__isInitialized__'));
     $serializer = new Serializer(array($normalizer), $encoders);
     $user = $this->getUser();
     $jsonContent = $serializer->serialize($user, 'xml');
     $response = new Response($jsonContent);
     $response->headers->set('Content-Type', 'text/xml');
     $response->headers->set('Content-Disposition', 'attachment; filename="pasport.xml"');
     return $response;
 }
Ejemplo n.º 4
0
 /**
  * pour rechercher des utilisateurs
  * @Route("/commenter", name="commenter")
  */
 public function commenter(Request $request)
 {
     $msg = $request->request->get('msg');
     $idAnnonce = $request->request->get('annonce');
     $user = $this->getConnectedUser();
     $commentaire = new comment();
     $commentaire->setIsVisible('YES');
     $commentaire->setUser($user);
     $commentaire->setMsg($msg);
     $now = new DateTime();
     $commentaire->setDate($now);
     $em = $this->getDoctrine()->getManager();
     $annonce = $em->getRepository("EntityBundle:annonce")->findOneById($idAnnonce);
     $commentaire->setAnnonce($annonce);
     $normalizer = new ObjectNormalizer();
     $normalizer->setIgnoredAttributes(array('password', 'comments', 'messages', 'username', 'role', 'roles', 'salt'));
     $serializer = new Serializer(array($normalizer), array(new JsonEncoder()));
     $em = $this->getDoctrine()->getManager();
     $em->persist($commentaire);
     $em->flush();
     $jsonContent = $serializer->serialize($commentaire, 'json');
     $response = new Response($jsonContent);
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }