src/Controller/HpvAnalysisAdminController.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Sonata\AdminBundle\Controller\CRUDController;
  5. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use App\Entity\HpvAnalysisClientResult;
  8. use App\Service\HpvAnalysisPdfGenerator;
  9. final class HpvAnalysisAdminController extends CRUDController
  10. {
  11.     private $hpvAnalysisPdfGenerator;
  12.     
  13.     private $hpvAnalysisAttachPdfFilename;
  14.     
  15.     public function __construct(HpvAnalysisPdfGenerator $hpvAnalysisPdfGeneratorstring $hpvAnalysisAttachPdfFilename) {
  16.         $this->hpvAnalysisPdfGenerator $hpvAnalysisPdfGenerator;
  17.         $this->hpvAnalysisAttachPdfFilename $hpvAnalysisAttachPdfFilename;
  18.     }
  19.     
  20.     public function pdfAction(Request $request)
  21.     {
  22.         /** @var HpvAnalysisClientResult $hpvAnalysisClientResult */
  23.         $hpvAnalysisClientResult $this->admin->getSubject();
  24.         
  25.         $pdfContent $this->hpvAnalysisPdfGenerator->generatePdfData($hpvAnalysisClientResult);
  26.         
  27.         $response = new Response($pdfContent);
  28.         $disposition $response->headers->makeDisposition(
  29.             ResponseHeaderBag::DISPOSITION_INLINE,
  30.             $this->hpvAnalysisAttachPdfFilename
  31.         );
  32.         
  33.         $response->headers->set('Content-Type''application/pdf');
  34.         $response->headers->set('Content-Disposition'$disposition);
  35.         
  36.         return $response;
  37.     }
  38.     
  39. }