refactoring: improve code quality

This commit is contained in:
Daniel Seifert 2025-01-21 23:47:20 +01:00
parent 9666276018
commit 5cff867c06
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
20 changed files with 230 additions and 407 deletions

View File

@ -8,6 +8,8 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Controller;
use D3\PdfDocuments\Application\Model\Exceptions\noPdfHandlerFoundException;
@ -20,12 +22,10 @@ use OxidEsales\Eshop\Core\Registry;
class orderOverviewPdfGenerator
{
/**
* @param Order $order
* @param int $iSelLang
* @throws noPdfHandlerFoundException
* @throws wrongPdfGeneratorInterface
*/
public function generatePdf(Order $order, int $iSelLang = 0)
public function generatePdf(Order $order, int $iSelLang = 0): void
{
$Pdf= $this->getPdfClass();
@ -38,7 +38,7 @@ class orderOverviewPdfGenerator
* @throws noPdfHandlerFoundException
* @throws wrongPdfGeneratorInterface
*/
public function getPdfClass()
public function getPdfClass(): pdfdocumentsOrderInterface
{
$requestedType = Registry::getRequest()->getRequestParameter('pdftype');
@ -51,7 +51,10 @@ class orderOverviewPdfGenerator
}
/** @var noPdfHandlerFoundException $e */
$e = oxNew(noPdfHandlerFoundException::class, Registry::getRequest()->getRequestParameter('pdftype'));
$e = oxNew(
noPdfHandlerFoundException::class,
Registry::getRequest()->getRequestParameter('pdftype')
);
throw($e);
}
}

View File

@ -8,25 +8,25 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\AbstractClasses;
use Assert\InvalidArgumentException;
use D3\PdfDocuments\Application\Model\Constants;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsGenericInterface as genericInterface;
use Exception;
use OxidEsales\Eshop\Core\Base;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\UtilsView;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRenderer;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface;
use OxidEsales\Twig\Resolver\TemplateChain\TemplateNotInChainException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Spipu\Html2Pdf\Exception\Html2PdfException;
use Spipu\Html2Pdf\Html2Pdf;
use Twig\Error\Error;
abstract class pdfdocumentsGeneric extends Base implements genericInterface
{
@ -40,10 +40,8 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
const PDF_ORIENTATION_PORTRAIT = 'P';
const PDF_ORIENTATION_LANDSCAPE = 'L';
public $filenameExtension = 'pdf';
/** @var string */
public $filename;
public string $filenameExtension = 'pdf';
public string $filename;
public function runPreAction()
{
@ -54,47 +52,34 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
}
/**
* @param string $sFilename
* @param int $iSelLang
* @param string $target
*
* @return string|null
* @throws ContainerExceptionInterface
* @throws Html2PdfException
* @throws NotFoundExceptionInterface
*/
public function genPdf($sFilename, $iSelLang = 0, $target = self::PDF_DESTINATION_STDOUT)
public function genPdf(string $filename, int $language = 0, string $target = self::PDF_DESTINATION_STDOUT): ?string
{
$oPdf = oxNew(Html2Pdf::class, ...$this->getPdfProperties());
$oPdf->setTestIsImage(false);
$htmlContent = $this->getHTMLContent($iSelLang);
$htmlContent = $this->getHTMLContent($language);
$oPdf->writeHTML($htmlContent);
$oPdf->pdf->setAuthor( Registry::getConfig()->getActiveShop()->getFieldData( 'oxname'));
$oPdf->pdf->setTitle( Registry::getLang()->translateString( $this->getTitleIdent()));
$oPdf->pdf->setCreator( 'D³ PDF Documents for OXID eShop');
$oPdf->pdf->setSubject( NULL);
return $this->output($oPdf, $sFilename, $target, $htmlContent);
return $this->output($oPdf, $filename, $target, $htmlContent);
}
/**
* @param int $iLanguage
* @throws Html2PdfException
*/
/**
* @param $iLanguage
*
* @return void
* @throws ContainerExceptionInterface
* @throws Html2PdfException
* @throws NotFoundExceptionInterface
*/
public function downloadPdf($iLanguage = 0)
public function downloadPdf(int $language = 0): void
{
try {
$this->runPreAction();
$sFilename = $this->getFilename();
$this->genPdf($sFilename, $iLanguage, self::PDF_DESTINATION_DOWNLOAD);
$this->genPdf($sFilename, $language, self::PDF_DESTINATION_DOWNLOAD);
$this->runPostAction();
Registry::getUtils()->showMessageAndExit('');
} catch (InvalidArgumentException $e) {
@ -104,22 +89,18 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
}
/**
* @param string $path
* @param int $iLanguage
*
* @return void
* @throws ContainerExceptionInterface
* @throws Html2PdfException
* @throws NotFoundExceptionInterface
*/
public function savePdfFile($path, $iLanguage = 0)
public function savePdfFile(string $path, int $language = 0): void
{
try {
$this->runPreAction();
$sFilename = $this->getFilename();
$this->genPdf(
rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$sFilename,
$iLanguage,
$language,
self::PDF_DESTINATION_FILE
);
$this->runPostAction();
@ -130,19 +111,16 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
}
/**
* @param int $iLanguage
*
* @return string|null
* @throws ContainerExceptionInterface
* @throws Html2PdfException
* @throws NotFoundExceptionInterface
*/
public function getPdfContent($iLanguage = 0)
public function getPdfContent(int $language = 0): ?string
{
try {
$this->runPreAction();
$sFilename = $this->getFilename();
$ret = $this->genPdf( $sFilename, $iLanguage, self::PDF_DESTINATION_STRING );
$ret = $this->genPdf( $sFilename, $language, self::PDF_DESTINATION_STRING );
$this->runPostAction();
return $ret;
} catch (InvalidArgumentException $e) {
@ -153,47 +131,37 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
return null;
}
public function getTemplateEngineVars(int $iSelLang): array
public function getTemplateEngineVars(int $language): array
{
unset($iSelLang);
unset($language);
return [
'config' => Registry::getConfig(),
'config' => Registry::getConfig(),
'oViewConf' => Registry::getConfig()->getActiveView()->getViewConfig(),
'shop' => Registry::getConfig()->getActiveShop(),
'lang' => Registry::getLang(),
'document' => $this
'shop' => Registry::getConfig()->getActiveShop(),
'lang' => Registry::getLang(),
'document' => $this
];
}
/**
* @param int $iSelLang
*
* @return mixed
* @throws InvalidArgumentException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getHTMLContent(int $iSelLang = 0)
public function getHTMLContent(int $language = 0): string
{
$blCurrentRenderFromAdmin = self::$_blIsAdmin;
self::$_blIsAdmin = $this->renderTemplateFromAdmin();
$lang = Registry::getLang();
$currTplLang = $lang->getTplLanguage();
$lang->setTplLanguage($iSelLang);
$lang->setTplLanguage($language);
$content = $this->getTemplateRenderer()->renderTemplate(
$this->getTemplate(),
$this->getTemplateEngineVars($language)
);
try {
$content = $this->getTemplateRenderer()->renderTemplate(
$this->getTemplate(),
$this->getTemplateEngineVars($iSelLang)
);
} catch (Error|TemplateNotInChainException $error) {
//Registry::getLogger()->error(dumpVar(__METHOD__." ".__LINE__), [$error->getFile()]);
throw oxNew(StandardException::class, $error->getMessage());
}
$lang->setTplLanguage($currTplLang);
self::$_blIsAdmin = $blCurrentRenderFromAdmin;
@ -201,6 +169,10 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
return $content;
}
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function getTemplateRenderer(): TemplateRenderer
{
return ContainerFactory::getInstance()->getContainer()
@ -208,41 +180,25 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
->getTemplateRenderer();
}
/**
* arguments for Html2Pdf class constructor
* - $orientation = 'P',
* - $format = 'A4',
* - $lang = 'fr',
* - $unicode = true,
* - $encoding = 'UTF-8',
* - $margins = array(5, 5, 5, 8),
* - $pdfa = false
* @return string[]
*/
public function getPdfProperties()
public function getPdfProperties(): array
{
$orientation = self::PDF_ORIENTATION_PORTRAIT;
$format = 'A4';
$lang = 'de';
$unicode = true;
$encoding = 'UTF-8';
$margins = [0, 0, 0, 0];
$pdfa = true;
return [$orientation, $format, $lang, $unicode, $encoding, $margins, $pdfa];
return [
'orientation' => self::PDF_ORIENTATION_PORTRAIT,
'format' => 'A4',
'lang' => 'de',
'unicode' => true,
'encoding' => 'UTF-8',
'margins' => [0, 0, 0, 0],
'pdfa' => true
];
}
/**
* @param $filename
*/
public function setFilename($filename)
public function setFilename(string $filename): void
{
$this->filename = $filename;
}
/**
* @return string
*/
public function getFilename()
public function getFilename(): string
{
// forced filename from setFilename()
if ($this->filename) {
@ -260,12 +216,7 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
);
}
/**
* @param string $filename
*
* @return string
*/
public function addFilenameExtension($filename)
public function addFilenameExtension(string $filename): string
{
$extension = $this->filenameExtension;
$extensionLength = (strlen($extension) + 1) * -1;
@ -278,12 +229,8 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
/**
* Gets proper file name
*
* @param $filename
*
* @return string
*/
public function makeValidFileName($filename)
public function makeValidFileName(string $filename): string
{
// sanitize filename
$filename = preg_replace(
@ -306,14 +253,14 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
// maximize filename length to 255 bytes
$ext = pathinfo($filename, PATHINFO_EXTENSION);
return mb_strcut(
pathinfo($filename, PATHINFO_FILENAME),
0,
255 - ($ext ? strlen($ext) + 1 : 0),
mb_detect_encoding($filename)
) . ($ext ? '.' . $ext : '');
pathinfo($filename, PATHINFO_FILENAME),
0,
255 - ($ext ? strlen($ext) + 1 : 0),
mb_detect_encoding($filename)
) . ($ext ? '.' . $ext : '');
}
public function beautifyFilename($filename)
public function beautifyFilename(string $filename): string
{
// reduce consecutive characters
$filename = preg_replace([
@ -341,64 +288,52 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
return trim($filename);
}
/**
* @return bool
*/
public function renderTemplateFromAdmin()
public function renderTemplateFromAdmin(): bool
{
return false;
}
/**
* @param Html2Pdf $oPdf
* @param $sFilename
* @param $target
* @param $html
*
* @return string|null
* @throws Html2PdfException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws Exception
*/
public function output(Html2Pdf $oPdf, $sFilename, $target, $html)
public function output(Html2Pdf $pdf, string $filename, string $target, string $html): ?string
{
$moduleSettings = ContainerFactory::getInstance()->getContainer()->get(ModuleSettingServiceInterface::class);
if ($moduleSettings->getBoolean( 'd3PdfDocumentsbDev', Constants::OXID_MODULE_ID )) {
return $this->outputDev($oPdf, $sFilename, $target, $html);
return $this->outputDev($pdf, $filename, $target, $html);
} else {
return $oPdf->output($sFilename, $target);
return $pdf->output($filename, $target);
}
}
/**
* @param Html2Pdf $oPdf
* @param $sFilename
* @param $target
* @param $html
* @return null
* @throws Exception
*/
public function outputDev(Html2Pdf $oPdf, $sFilename, $target, $html)
public function outputDev(Html2Pdf $pdf, string $filename, string $target, string $html): ?string
{
$sFilename = str_replace('.pdf', '.html', $sFilename);
$filename = str_replace('.pdf', '.html', $filename);
switch($target) {
case 'I': {
// Send PDF to the standard output
if (ob_get_contents()) {
$oPdf->pdf->Error('Some data has already been output, can\'t send PDF file');
$pdf->pdf->Error('Some data has already been output, can\'t send PDF file');
}
if (substr(php_sapi_name(), 0, 3) != 'cli') {
//We send to a browser
if (!str_starts_with(php_sapi_name(), 'cli')) {
// send to browser
header('Content-Type: text/html');
if (headers_sent()) {
$oPdf->pdf->Error('Some data has already been output to browser, can\'t send PDF file');
$pdf->pdf->Error('Some data has already been output to browser, can\'t send PDF file');
}
header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Content-Length: '.strlen($html));
header('Content-Disposition: inline; filename="'.basename($sFilename).'";');
header('Content-Disposition: inline; filename="'.basename($filename).'";');
}
echo $html;
break;
@ -406,11 +341,11 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
case 'D': {
// Download PDF as file
if (ob_get_contents()) {
$oPdf->pdf->Error('Some data has already been output, can\'t send PDF file');
$pdf->pdf->Error('Some data has already been output, can\'t send PDF file');
}
header('Content-Description: File Transfer');
if (headers_sent()) {
$oPdf->pdf->Error('Some data has already been output to browser, can\'t send PDF file');
$pdf->pdf->Error('Some data has already been output to browser, can\'t send PDF file');
}
header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
header('Pragma: public');
@ -422,7 +357,7 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
header('Content-Type: application/download', false);
header('Content-Type: text/html', false);
// use the Content-Disposition header to supply a recommended filename
header('Content-Disposition: attachment; filename="'.basename($sFilename).'";');
header('Content-Disposition: attachment; filename="'.basename($filename).'";');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.strlen($html));
echo $html;
@ -430,20 +365,20 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
}
case 'F': {
// Save PDF to a local file
$f = fopen($sFilename, 'wb');
$f = fopen($filename, 'wb');
if (!$f) {
$oPdf->pdf->Error('Unable to create output file: '.$sFilename);
$pdf->pdf->Error('Unable to create output file: '.$filename);
}
fwrite($f, $html, strlen($html));
fclose($f);
break;
}
case 'S': {
// Returns PDF as a string
// Return PDF as a string
return $html;
}
default: {
$oPdf->pdf->Error('Incorrect output destination: '.$target);
$pdf->pdf->Error('Incorrect output destination: '.$target);
}
}

View File

@ -8,6 +8,8 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\AbstractClasses;
use Assert\Assert;
@ -20,8 +22,7 @@ use OxidEsales\Eshop\Core\Registry;
abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInterface
{
/** @var Order */
public $oOrder;
public Order $order;
/**
* don't use order as constructor argument because of same method interface for all document types
@ -31,55 +32,49 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt
parent::__construct();
}
/**
* @param Order $order
*/
public function setOrder(Order $order)
public function setOrder(Order $order): void
{
$this->oOrder = $order;
$this->order = $order;
}
/**
* @throws InvalidArgumentException
* @return Order
*/
public function getOrder()
public function getOrder(): Order
{
Assert::lazy()
->that($this->oOrder)->isInstanceOf(Order::class, 'no order for pdf generator set')
->that($this->oOrder->isLoaded())->true('given order is not loaded')
->that($this->order)->isInstanceOf(Order::class, 'no order for pdf generator set')
->that($this->order->isLoaded())->true('given order is not loaded')
->verifyNow();
return $this->oOrder;
return $this->order;
}
/**
* @param int $iSelLang
* @throws InvalidArgumentException
*/
public function getTemplateEngineVars($iSelLang): array
public function getTemplateEngineVars(int $language): array
{
$oUser = oxNew(User::Class);
$oUser->load($this->getOrder()->getFieldData('oxuserid'));
$oPayment = oxNew(Payment::class);
$oPayment->loadInLang($iSelLang, $this->getOrder()->getFieldData('oxpaymenttype'));
$oPayment->loadInLang($language, $this->getOrder()->getFieldData('oxpaymenttype'));
return array_merge(
parent::getTemplateEngineVars($iSelLang),
parent::getTemplateEngineVars($language),
[
'order' => $this->getOrder(),
'user' => $oUser,
'order' => $this->getOrder(),
'user' => $oUser,
'payment' => $oPayment
]
);
}
/**
* @return string
* @throws InvalidArgumentException
*/
public function getFilename()
public function getFilename(): string
{
// forced filename from setFilename()
if ($this->filename) {
@ -106,23 +101,12 @@ abstract class pdfdocumentsOrder extends pdfdocumentsGeneric implements orderInt
);
}
/**
* @return int
*/
public function getPaymentTerm()
public function getPaymentTerm(): int
{
if (null === $iPaymentTerm = Registry::getConfig()->getConfigParam('iPaymentTerm')) {
$iPaymentTerm = 7;
}
return $iPaymentTerm;
return (int) Registry::getConfig()->getConfigParam('iPaymentTerm') ?? 7;
}
/**
* @return false|int
* @throws InvalidArgumentException
*/
public function getPayableUntilDate()
public function getPayableUntilDate(): false|int
{
return strtotime(
'+' . $this->getPaymentTerm() . ' day',

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace D3\PdfDocuments\Application\Model;
class Constants
{
public const OXID_MODULE_ID = 'd3PdfDocuments';

View File

@ -8,40 +8,30 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Documents;
use D3\PdfDocuments\Application\Model\AbstractClasses\pdfdocumentsOrder;
class deliverynotePdf extends pdfdocumentsOrder
{
/**
* @return string
*/
public function getRequestId()
public function getRequestId(): string
{
return 'dnote';
}
/**
* @return string
*/
public function getTitleIdent()
public function getTitleIdent(): string
{
return "D3_PDFDOCUMENTS_DELIVERYNOTE";
}
/**
* @return string
*/
public function getTypeForFilename()
public function getTypeForFilename(): string
{
return 'delnote';
}
/**
* @return string
*/
public function getTemplate()
public function getTemplate(): string
{
return '@d3PdfDocuments/documents/deliverynote/deliverynote';
}

View File

@ -8,38 +8,28 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Documents;
class deliverynotewithoutlogoPdf extends deliverynotePdf
{
/**
* @return string
*/
public function getRequestId()
public function getRequestId(): string
{
return 'dnote_without_logo';
}
/**
* @return string
*/
public function getTitleIdent()
public function getTitleIdent(): string
{
return "D3_PDFDOCUMENTS_DELIVERYNOTE_WITHOUT_LOGO";
}
/**
* @return string
*/
public function getTypeForFilename()
public function getTypeForFilename(): string
{
return 'delnote-nl';
}
/**
* @return string
*/
public function getTemplate()
public function getTemplate(): string
{
return '@d3PdfDocuments/documents/deliverynote/deliverynoteNoLogo';
}

View File

@ -8,45 +8,33 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Documents;
use Assert\InvalidArgumentException;
use D3\PdfDocuments\Application\Model\AbstractClasses\pdfdocumentsOrder;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderinvoiceInterface;
class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceInterface
{
protected $blIsNewOrder = false;
protected bool $isNewOrder = false;
/**
* @return string
*/
public function getRequestId()
public function getRequestId(): string
{
return 'invoice';
}
/**
* @return string
*/
public function getTitleIdent()
public function getTitleIdent(): string
{
return "D3_PDFDOCUMENTS_INVOICE";
}
/**
* @return string
*/
public function getTypeForFilename()
public function getTypeForFilename(): string
{
return 'invoice';
}
/**
* @return void
* @throws InvalidArgumentException
*/
public function runPreAction()
public function runPreAction(): void
{
parent::runPreAction();
@ -55,54 +43,39 @@ class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceIn
$this->saveOrderOnChanges();
}
/**
* @return void
* @throws InvalidArgumentException
*/
public function setInvoiceNumber()
public function setInvoiceNumber(): void
{
if (!$this->getOrder()->getFieldData('oxbillnr')) {
$this->getOrder()->assign(['oxbillnr' => $this->getOrder()->getNextBillNum()]);
$this->blIsNewOrder = true;
$this->isNewOrder = true;
}
}
/**
* @return void
* @throws InvalidArgumentException
*/
public function setInvoiceDate()
public function setInvoiceDate(): void
{
if ($this->getOrder()->getFieldData('oxbilldate') == '0000-00-00') {
$this->getOrder()->assign([
"oxbilldate" => date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y')))
"oxbilldate" => date('Y-m-d')
]);
$this->blIsNewOrder = true;
$this->isNewOrder = true;
}
}
/**
* @return void
* @throws InvalidArgumentException
*/
public function saveOrderOnChanges()
public function saveOrderOnChanges(): void
{
if ($this->blIsNewOrder) {
if ($this->isNewOrder) {
$this->getOrder()->save();
}
}
public function getTemplate(){
public function getTemplate(): string
{
return '@d3PdfDocuments/documents/invoice/invoice';
}
/**
* @return string
* @throws InvalidArgumentException
*/
public function getFilename()
public function getFilename(): string
{
$filename = parent::getFilename();

View File

@ -8,38 +8,28 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Documents;
class invoicewithoutlogoPdf extends invoicePdf
{
/**
* @return string
*/
public function getRequestId()
public function getRequestId(): string
{
return 'invoice_without_logo';
}
/**
* @return string
*/
public function getTitleIdent()
public function getTitleIdent(): string
{
return "D3_PDFDOCUMENTS_INVOICE_WITHOUT_LOGO";
}
/**
* @return string
*/
public function getTypeForFilename()
public function getTypeForFilename(): string
{
return 'invoice-nl';
}
/**
* @return string
*/
public function getTemplate()
public function getTemplate(): string
{
return '@d3PdfDocuments/documents/invoice/invoiceNoLogo';
}

View File

@ -8,23 +8,21 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Exceptions;
use Exception;
class noPdfHandlerFoundException extends pdfGeneratorExceptionAbstract
{
/**
* d3noPdfHandlerFoundException constructor.
*
* @param $requestId
* @param string $sMessage
* @param int $iCode
* @param Exception|null $previous
*/
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 );
public function __construct(
$requestId,
string $message = "no pdf handler defined for given request id",
int $code = 0,
?Exception $previous = null
) {
$message .= ' "'.$requestId.'"';
parent::__construct( $message, $code, $previous );
}
}

View File

@ -8,6 +8,8 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Exceptions;
use OxidEsales\Eshop\Core\Exception\StandardException;

View File

@ -8,16 +8,21 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Exceptions;
use Exception;
class wrongPdfGeneratorInterface extends pdfGeneratorExceptionAbstract
{
public function __construct( $requiredInterface, $sMessage = "generator class doesn't fulfilled the interface", $iCode = 0, Exception $previous = null ) {
$sMessage .= $requiredInterface;
parent::__construct( $sMessage, $iCode, $previous );
public function __construct(
string $requiredInterface,
string $message = "generator class doesn't fulfilled the interface",
int $code = 0,
Exception $previous = null
) {
$message .= $requiredInterface;
parent::__construct( $message, $code, $previous );
}
}

View File

@ -8,71 +8,31 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Interfaces;
interface pdfdocumentsGenericInterface
{
/**
* @return string
*/
public function getRequestId();
public function getRequestId(): string;
/**
* @return string
*/
public function getTitleIdent();
public function getTitleIdent(): string;
/**
* @return string
*/
public function getTemplate();
public function getTemplate(): string;
/**
* @return mixed
*/
public function getHTMLContent();
public function getHTMLContent(): string;
/**
* @param int $iLanguage
*/
public function downloadPdf(int $iLanguage = 0);
public function downloadPdf(int $language = 0): void;
/**
* @param int $iLanguage
*
* @return string|null
*/
public function getPdfContent(int $iLanguage = 0);
public function getPdfContent(int $language = 0): ?string;
/**
* @param string $path
* @param int $iLanguage
*/
public function savePdfFile(string $path, int $iLanguage = 0);
public function savePdfFile(string $path, int $language = 0): void;
/**
* @param string $sFilename
* @param int $iSelLang
* @param string $target
*
* @return mixed
*/
public function genPdf(string $sFilename, int $iSelLang = 0, string $target = 'I');
public function genPdf(string $filename, int $language = 0, string $target = 'I'): ?string;
/**
* @param string $filename
*/
public function setFilename($filename);
public function setFilename(string $filename): void;
/**
* @return string
*/
public function getFilename();
public function getFilename(): string;
/**
* @param string $filename
*
* @return string
*/
public function addFilenameExtension($filename);
public function addFilenameExtension(string $filename): string;
}

View File

@ -8,6 +8,8 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Interfaces;
use Assert\InvalidArgumentException;
@ -15,19 +17,9 @@ use OxidEsales\Eshop\Application\Model\Order;
interface pdfdocumentsOrderInterface extends pdfdocumentsGenericInterface
{
/**
* @param Order $order
*/
public function setOrder(Order $order);
public function setOrder(Order $order): void;
/**
* @throws InvalidArgumentException
* @return Order
*/
public function getOrder();
public function getOrder(): Order;
/**
* @return string
*/
public function getTypeForFilename();
public function getTypeForFilename(): string;
}

View File

@ -8,11 +8,13 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Interfaces;
interface pdfdocumentsOrderinvoiceInterface extends pdfdocumentsOrderInterface
{
public function setInvoiceNumber();
public function setInvoiceNumber(): void;
public function setInvoiceDate();
public function setInvoiceDate(): void;
}

View File

@ -8,6 +8,8 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Registries;
use D3\PdfDocuments\Application\Model\Exceptions\wrongPdfGeneratorInterface;
@ -16,22 +18,17 @@ use OxidEsales\Eshop\Core\Exception\StandardException;
abstract class registryAbstract implements registryGenericInterface
{
protected $_aRegistry = array();
protected array $registry = [];
/**
* @return string
*/
public function getRequiredGeneratorInterfaceClassName()
public function getRequiredGeneratorInterfaceClassName(): string
{
return pdfdocumentsGenericInterface::class;
}
/**
* @param $className
*
* @throws wrongPdfGeneratorInterface
*/
public function addGenerator($className)
public function addGenerator(string $className): void
{
if ( ! $this->hasGenerator( $className ) ) {
/** @var pdfdocumentsGenericInterface $generator */
@ -44,28 +41,30 @@ abstract class registryAbstract implements registryGenericInterface
}
/**
* @param $className * generator fully qualified class name
* @param string $className * generator fully qualified class name
* @param pdfdocumentsGenericInterface $item
* @throws wrongPdfGeneratorInterface
*/
protected function addItem($className, pdfdocumentsGenericInterface $item)
protected function addItem(string $className, pdfdocumentsGenericInterface $item): void
{
$requiredInterface = $this->getRequiredGeneratorInterfaceClassName();
if ( ! $item instanceof $requiredInterface ) {
throw oxNew(wrongPdfGeneratorInterface::class, $requiredInterface);
/** @var wrongPdfGeneratorInterface $exception */
$exception = oxNew(wrongPdfGeneratorInterface::class, $requiredInterface);
throw $exception;
}
$this->_aRegistry[$className] = $item;
$this->registry[$className] = $item;
}
/**
* @param $className * generator fully qualified class name
* @param string $className * generator fully qualified class name
*/
public function removeGenerator($className)
public function removeGenerator(string $className): void
{
if ($this->hasGenerator($className)) {
unset( $this->_aRegistry[ $className ] );
unset( $this->registry[ $className ] );
}
}
@ -73,21 +72,18 @@ abstract class registryAbstract implements registryGenericInterface
* @param $className * generator fully qualified class name
* @return bool
*/
public function hasGenerator($className)
public function hasGenerator(string $className): bool
{
return array_key_exists($className, $this->_aRegistry);
return array_key_exists($className, $this->registry);
}
/**
* @return array
*/
public function getList()
public function getList(): array
{
return $this->_aRegistry;
return $this->registry;
}
public function clearList()
public function clearList(): void
{
$this->_aRegistry = [];
$this->registry = [];
}
}

View File

@ -8,31 +8,32 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Registries;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsGenericInterface;
interface registryGenericInterface
{
public function getRequiredGeneratorInterfaceClassName();
public function getRequiredGeneratorInterfaceClassName(): string;
/**
* @param $className * generator fully qualified class name
*/
public function removeGenerator($className);
public function removeGenerator(string $className): void;
/**
* @param $className * generator fully qualified class name
*/
public function hasGenerator($className);
public function hasGenerator(string $className): bool;
/**
* @param $className * generator fully qualified class name
*/
public function getGenerator($className);
public function getGenerator(string $className): pdfdocumentsGenericInterface;
/**
* @return array
*/
public function getList();
public function getList(): array;
public function clearList();
public function clearList(): void;
}

View File

@ -8,6 +8,8 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Registries;
use D3\PdfDocuments\Application\Model\Documents\deliverynotePdf;
@ -15,6 +17,7 @@ use D3\PdfDocuments\Application\Model\Documents\deliverynotewithoutlogoPdf;
use D3\PdfDocuments\Application\Model\Documents\invoicePdf;
use D3\PdfDocuments\Application\Model\Documents\invoicewithoutlogoPdf;
use D3\PdfDocuments\Application\Model\Exceptions\wrongPdfGeneratorInterface;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsGenericInterface;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderInterface;
class registryOrdermanagerActions extends registryAbstract implements registryOrdermanagerActionsInterface
@ -30,20 +33,17 @@ class registryOrdermanagerActions extends registryAbstract implements registryOr
$this->addGenerator(deliverynotewithoutlogoPdf::class);
}
/**
* @return string
*/
public function getRequiredGeneratorInterfaceClassName()
public function getRequiredGeneratorInterfaceClassName(): string
{
return pdfdocumentsOrderInterface::class;
}
/**
* @param $className * generator fully qualified class name
* @param string $className * generator fully qualified class name
* @return pdfdocumentsOrderInterface
*/
public function getGenerator($className)
public function getGenerator(string $className): pdfdocumentsOrderInterface
{
return $this->_aRegistry[$className];
return $this->registry[$className];
}
}

View File

@ -8,12 +8,14 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Registries;
interface registryOrdermanagerActionsInterface extends registryGenericInterface
{
/**
* @param $className * generator fully qualified class name
* @param string $className * generator fully qualified class name
*/
public function addGenerator($className);
public function addGenerator(string $className): void;
}

View File

@ -8,6 +8,8 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Registries;
use D3\PdfDocuments\Application\Model\Documents\deliverynotePdf;
@ -30,20 +32,17 @@ class registryOrderoverview extends registryAbstract implements registryOrderove
$this->addGenerator(deliverynotewithoutlogoPdf::class);
}
/**
* @return string
*/
public function getRequiredGeneratorInterfaceClassName()
public function getRequiredGeneratorInterfaceClassName(): string
{
return pdfdocumentsOrderInterface::class;
}
/**
* @param $className * generator fully qualified class name
* @param string $className * generator fully qualified class name
* @return pdfdocumentsOrderInterface
*/
public function getGenerator($className)
public function getGenerator(string $className): pdfdocumentsOrderInterface
{
return $this->_aRegistry[$className];
return $this->registry[$className];
}
}

View File

@ -8,12 +8,14 @@
* @link http://www.oxidmodule.com
*/
declare(strict_types = 1);
namespace D3\PdfDocuments\Application\Model\Registries;
interface registryOrderoverviewInterface extends registryGenericInterface
{
/**
* @param $className * generator fully qualified class name
* @param string $className * generator fully qualified class name
*/
public function addGenerator($className);
public function addGenerator(string $className): void;
}