change impl to avoid compilation issue

This commit is contained in:
troosan 2017-12-29 21:47:55 +01:00
parent 2d87fd320d
commit 23693b403c
1 changed files with 25 additions and 7 deletions

View File

@ -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';
}
}