pdfService = $pdfService; $this->maintenanceManager = $maintenanceManagerService; } /** * @param ServerRequestInterface $request * @param DelegateInterface $delegate * @return \Zend\Diactoros\Response\JsonResponse|TextResponse|static * @throws \PHPPdf\Core\PHPPdf\Exception\Exception */ public function get(ServerRequestInterface $request, DelegateInterface $delegate) { $id = $request->getAttribute('id', false); try { return (new TextResponse($this->pdfService->getMaintenanceSheet($id))) ->withHeader('Content-type', 'application/pdf'); } catch (\Exception $e) { return new TextResponse($e->getMessage(), 500); } } /** * Configure CORS preflight * * @param ServerRequestInterface $request * @param DelegateInterface $delegate * @return static */ public function options(ServerRequestInterface $request, DelegateInterface $delegate) { return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS); } }