From 5ffd0719545b4fd5f633feeaa18f90e491e2b91c Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 29 May 2020 09:58:53 +0200 Subject: [PATCH] throw exception in case of undefined pdf request type --- Application/Controller/orderPdfGenerator.php | 14 +++++----- .../d3noPdfHandlerFoundException.php | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 Application/Model/Exceptions/d3noPdfHandlerFoundException.php diff --git a/Application/Controller/orderPdfGenerator.php b/Application/Controller/orderPdfGenerator.php index bcdb386..e701bd1 100644 --- a/Application/Controller/orderPdfGenerator.php +++ b/Application/Controller/orderPdfGenerator.php @@ -17,6 +17,7 @@ namespace D3\PdfDocuments\Application\Controller; use D3\PdfDocuments\Application\Model\Documents\deliverynotePdf; use D3\PdfDocuments\Application\Model\Documents\invoicePdf; +use D3\PdfDocuments\Application\Model\Exceptions\d3noPdfHandlerFoundException; use D3\PdfDocuments\Application\Model\Interfaces\pdfdocuments_order_interface as OrderPdfInterface; use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Core\Registry; @@ -60,16 +61,17 @@ echo __CLASS__." - ".__FUNCTION__." - ".__LINE__."
"; } /** + * @param Order $order + * * @return OrderPdfInterface - * @throws \OxidEsales\Eshop\Core\Exception\SystemComponentException - * @throws \oxSystemComponentException + * @throws d3noPdfHandlerFoundException */ public function getCustomPdfClass(Order $order) { -echo __CLASS__." - ".__FUNCTION__." - ".__LINE__."
"; - $pdfInvoice= oxNew(invoicePdf::class); - $pdfInvoice->setOrder($order); + unset($order); - return $pdfInvoice; + /** @var d3noPdfHandlerFoundException $e */ + $e = oxNew(d3noPdfHandlerFoundException::class, Registry::getRequest()->getRequestParameter('pdftype')); + throw($e); } } \ No newline at end of file diff --git a/Application/Model/Exceptions/d3noPdfHandlerFoundException.php b/Application/Model/Exceptions/d3noPdfHandlerFoundException.php new file mode 100644 index 0000000..2eb2c3a --- /dev/null +++ b/Application/Model/Exceptions/d3noPdfHandlerFoundException.php @@ -0,0 +1,27 @@ + + * @link http://www.oxidmodule.com + */ + +namespace D3\PdfDocuments\Application\Model\Exceptions; + +use OxidEsales\Eshop\Core\Exception\StandardException; + +class d3noPdfHandlerFoundException extends StandardException +{ + public function __construct( $requestId, $sMessage = "no pdf handler defined for given request id", $iCode = 0, \Exception $previous = null ) + { + $sMessage .= '"'.$requestId.'"'; + parent::__construct( $sMessage, $iCode, $previous ); + } +} \ No newline at end of file