* initial commit

This commit is contained in:
Danyi Dávid
2018-11-11 12:01:18 +01:00
commit 17ec066110
165 changed files with 20529 additions and 0 deletions

View 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);
}
}