public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school');
     $appForm = $this->appFormService->findSchoolApplicationForm($school->id);
     if (null === $appForm) {
         return $res->withStatus(404);
     }
     $html = $this->view->fetch('application_form/pdf.twig', ['school' => $school, 'appForm' => $appForm, 'logo' => base64_encode(file_get_contents(__DIR__ . '/../../public/img/application_form/minedu_logo.jpg')), 'style' => file_get_contents(__DIR__ . '/../../public/css/application_form/pdf.css')]);
     $pdf = new \Dompdf\Dompdf(['default_paper_size' => 'A4', 'default_font' => 'DejaVu Sans', 'isHtml5ParserEnabled' => true, 'is_remote_enabled' => false]);
     $pdf->loadHtml($html);
     $pdf->render();
     $filename = 'edulabs_app_form_' . $appForm['id'] . '.pdf';
     $str = $pdf->output();
     $length = mb_strlen($str, '8bit');
     return $res->withHeader('Cache-Control', 'private')->withHeader('Content-type', 'application/pdf')->withHeader('Content-Length', $length)->withHeader('Content-Disposition', 'attachment;  filename=' . $filename)->withHeader('Accept-Ranges', $length)->write($str);
 }
 public function testMultipleTemplatesWithMulNamespace()
 {
     $views = new Twig(['One' => __DIR__ . '/templates', 'Two' => __DIR__ . '/another']);
     $outputOne = $views->fetch('@One/example.html', ['name' => 'Peter']);
     $outputTwo = $views->fetch('@Two/example.html', ['name' => 'Peter', 'gender' => 'male']);
     $this->assertEquals("<p>Hi, my name is Peter.</p>\n", $outputOne);
     $this->assertEquals("<p>Hi, my name is Peter and I am male.</p>\n", $outputTwo);
 }
Exemple #3
0
 public function testMultipleDirectoriesWithoutNamespaces()
 {
     $weekday = (new \DateTimeImmutable('2016-03-08'))->format('l');
     $view = new Twig([__DIR__ . '/multi/', __DIR__ . '/another/']);
     $rootDirectory = $view->fetch('directory/template/example.html', ['weekday' => $weekday]);
     $multiDirectory = $view->fetch('another_example.html', ['name' => 'Peter', 'gender' => 'male']);
     $this->assertEquals('Happy Tuesday!', $rootDirectory);
     $this->assertEquals("<p>Hi, my name is Peter and I am male.</p>\n", $multiDirectory);
 }
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Exception $exception)
 {
     $helper = new ErrorHelper($exception, $this->option('exceptions_with_code'), $this->option('exceptions_without_code'), $this->option('exceptions_with_messages'));
     $helper->setKnownTypes($this->option('allowed_content_types'));
     // Detect content type from header
     $response = $response->withHeader('Content-type', $helper->detectContentType($request));
     // Check for passed content-type callable in options
     if ($this->contentTypeCallable) {
         $response = call_user_func($this->contentTypeCallable, $request, $response);
     }
     $contentType = $response->getHeader('Content-type')[0];
     // Detect status code from the exception
     $statusCode = $helper->detectStatusCode();
     // Use view if available
     $view = null;
     if ($this->view) {
         $view = function ($errorData, $template) {
             return $this->view->fetch($template, $errorData);
         };
     }
     $output = '';
     switch ($contentType) {
         case 'application/json':
             $output = $helper->renderJsonErrorResponse($this->displayErrorDetails, $this->option('json_encode_options'));
             break;
         case 'text/xml':
         case 'application/xml':
             $output = $helper->renderXmlErrorResponse($this->displayErrorDetails, $view, $this->option('xml_template_path'));
             break;
         case 'text/html':
             $output = $helper->renderHtmlErrorResponse($this->displayErrorDetails, $view, $this->option('html_template_path'));
             break;
     }
     $body = new Body(fopen('php://temp', 'r+'));
     $body->write($output);
     return $response->withStatus($statusCode)->withBody($body);
 }
 public function testFetch()
 {
     $output = $this->view->fetch('example.html', ['name' => 'Josh']);
     $this->assertEquals("<p>Hi, my name is Josh.</p>\n", $output);
 }