public function testNormalizeNotSerializableContext()
 {
     $objectDummy = new ObjectDummy();
     $expected = array('foo' => null, 'baz' => null, 'fooBar' => '', 'camelCase' => null, 'object' => null, 'bar' => null);
     $this->assertEquals($expected, $this->normalizer->normalize($objectDummy, null, array('not_serializable' => function () {
     })));
 }
Ejemplo n.º 2
0
 /**
  * @Route("/exportcsvpro", name="export_pro")
  */
 public function exportProCSVAction()
 {
     $now = new \DateTime('now');
     $em = $this->getDoctrine()->getManager();
     $response = new StreamedResponse();
     $response->setCallback(function () use($em) {
         $normalizer = new ObjectNormalizer();
         $count = $em->getRepository('AppBundle:Client')->getCount();
         $total = intval($count[1]);
         $header = array('NOM', 'PRENOM', 'EMAIL', 'SEXE');
         $handle = fopen('php://output', 'r+');
         fputcsv($handle, $header, ";");
         $row = 1;
         while ($total >= 0) {
             $clients = $em->getRepository('AppBundle:Client')->findAllClients(($row - 1) * 2, 2);
             foreach ($clients as $key => $obj) {
                 $clients[$key] = $normalizer->normalize($obj);
             }
             foreach ($clients as $client) {
                 fputcsv($handle, $client, ";");
             }
             $total = $total - 2;
             $row++;
         }
         fclose($handle);
     });
     $response->headers->set('Content-Type', 'application/force-download');
     $response->headers->set('Content-Disposition', 'attachment; filename="export.csv"');
     return $response;
 }
 /**
  * @Route("/exportexcel", requirements={"_format" = "excel"}, name="excel_export")
  */
 public function exportExcelAction()
 {
     if ($this->getRequest()->getMethod() == "POST") {
         $normalizer = new ObjectNormalizer();
         $now = new \DateTime();
         $day = $now->format('d');
         $month = $now->format('m');
         $year = $now->format('Y');
         $date = $day . '-' . $month . '-' . $year;
         $filename = 'export_articles_' . $date . '.xls';
         $em = $this->getDoctrine()->getManager();
         $data = $em->getRepository('AppBundle:Article')->findAll();
         foreach ($data as $key => $obj) {
             $data[$key] = $normalizer->normalize($obj);
         }
         return $this->get('excel_service')->array_to_excel($data, $filename);
         die;
     }
     return $this->render('AppBundle:Default:exportexcel.html.twig');
 }
 public function testNormalizeStatic()
 {
     $this->assertEquals(array('foo' => 'K'), $this->normalizer->normalize(new ObjectWithStaticPropertiesAndMethods()));
 }