From 23693b403c32c13a355adf0e2a32642a480066da Mon Sep 17 00:00:00 2001 From: troosan Date: Fri, 29 Dec 2017 21:47:55 +0100 Subject: [PATCH] change impl to avoid compilation issue --- src/PhpWord/Writer/PDF/MPDF.php | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/PhpWord/Writer/PDF/MPDF.php b/src/PhpWord/Writer/PDF/MPDF.php index e238057b..b6980a9d 100644 --- a/src/PhpWord/Writer/PDF/MPDF.php +++ b/src/PhpWord/Writer/PDF/MPDF.php @@ -29,6 +29,12 @@ use PhpOffice\PhpWord\Writer\WriterInterface; */ class MPDF extends AbstractRenderer implements WriterInterface { + /** + * Overridden to set the correct includefile, only needed for MPDF 5 + * + * @codeCoverageIgnore + * @param PhpWord $phpWord + */ public function __construct(PhpWord $phpWord) { if (file_exists(Settings::getPdfRendererPath() . '/mpdf.php')) { @@ -52,13 +58,8 @@ class MPDF extends AbstractRenderer implements WriterInterface $orientation = strtoupper('portrait'); // Create PDF - if ($this->includeFile != null) { - // MPDF version 5.* - $pdf = new \mpdf(); - } else { - // MPDF version > 6.* - $pdf = new \Mpdf\Mpdf(); - } + $mPdfClass = $this->getMPdfClassName(); + $pdf = new $mPdfClass(); $pdf->_setPageSize($paperSize, $orientation); $pdf->addPage($orientation); @@ -78,4 +79,21 @@ class MPDF extends AbstractRenderer implements WriterInterface parent::restoreStateAfterSave($fileHandle); } + + /** + * Return classname of MPDF to instantiate + * + * @codeCoverageIgnore + * @return string + */ + private function getMPdfClassName() + { + if ($this->includeFile != null) { + // MPDF version 5.* + return '\mpdf'; + } + + // MPDF version > 6.* + return '\Mpdf\Mpdf'; + } }