* initial commit
This commit is contained in:
63
src/App/Action/Pdf/GenerateMaintenanceSheetAction.php
Normal file
63
src/App/Action/Pdf/GenerateMaintenanceSheetAction.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Pdf;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use App\Service\PdfService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Diactoros\Response\TextResponse;
|
||||
|
||||
class GenerateMaintenanceSheetAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var PdfService
|
||||
*/
|
||||
private $pdfService;
|
||||
|
||||
/**
|
||||
* @var MaintenanceManagerService
|
||||
*/
|
||||
private $maintenanceManager;
|
||||
|
||||
public function __construct(PdfService $pdfService, MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user