From d4589d20918f8593b824afe9b858cac4470c10ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20=C5=A0korpil?= Date: Wed, 3 Jan 2018 15:56:20 +0100 Subject: [PATCH] feat: upgraded dependency to Mpdf v7, added support for PHP v7.2 BREAKING CHANGE: minimal compatibility set to PHP v5.6 close #21 --- .travis.yml | 4 +- composer.json | 6 +- .../Application/Responses/PdfResponse.php | 55 +++++++++++------- tests/PdfResponse/expected/full.pdf | Bin 28315 -> 28319 bytes tests/PdfResponse/expected/page.format.pdf | Bin 28305 -> 28309 bytes .../PdfResponse/expected/symfony.crawler.pdf | Bin 28234 -> 28238 bytes 6 files changed, 38 insertions(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index bcc19e2..41b9c3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,9 @@ language: php php: - - 5.4 - - 5.5 - 5.6 - 7.0 - 7.1 - + - 7.2 matrix: allow_failures: - php: hhvm diff --git a/composer.json b/composer.json index 84a3c04..94fa329 100644 --- a/composer.json +++ b/composer.json @@ -15,12 +15,12 @@ } ], "require": { - "php": ">=5.4 || ~7.0.0 || ~7.1.0", - "mpdf/mpdf": "~6.1.3" + "php": ">=5.6 || ~7.0.0 || ~7.1.0 || ~7.2.0", + "mpdf/mpdf": "~7.0.0" }, "require-dev": { "nette/application": "~2.2", - "nette/tester": "~1.0", + "nette/tester": "~2.0", "symfony/dom-crawler": "~2.5", "symfony/css-selector": "~2.5", "latte/latte": "~2.2" diff --git a/src/Joseki/Application/Responses/PdfResponse.php b/src/Joseki/Application/Responses/PdfResponse.php index a27cf20..0c1bb3c 100644 --- a/src/Joseki/Application/Responses/PdfResponse.php +++ b/src/Joseki/Application/Responses/PdfResponse.php @@ -2,7 +2,7 @@ namespace Joseki\Application\Responses; -use mPDF; +use Mpdf\Mpdf; use Nette; use Nette\Bridges\ApplicationLatte\Template; use Nette\FileNotFoundException; @@ -20,6 +20,7 @@ * @author Jan Kuchař * @author Tomáš Votruba * @author Miroslav Paulík + * @author Štěpán Škorpil * @copyright Copyright (c) 2010 Jan Kuchař (http://mujserver.net) * @license LGPL * @link http://addons.nette.org/cs/pdfresponse2 @@ -37,8 +38,10 @@ * @property bool $ignoreStylesInHTMLDocument * @method onBeforeComplete($mpdf) @internal */ -class PdfResponse extends Nette\Object implements Nette\Application\IResponse +class PdfResponse implements Nette\Application\IResponse { + use Nette\SmartObject; + /** possible save modes */ const INLINE = "I"; @@ -106,7 +109,7 @@ class PdfResponse extends Nette\Object implements Nette\Application\IResponse /** @var string margins: top, right, bottom, left, header, footer */ private $pageMargins = "16,15,16,15,9,9"; - /** @var mPDF */ + /** @var Mpdf */ private $mPDF = null; /** @var mPDF */ @@ -412,28 +415,37 @@ public function setBackgroundTemplate($pathToBackgroundTemplate) + /** + * @return array + */ + protected function getMPDFConfig() + { + $margins = $this->getMargins(); + return [ + 'mode' => 'utf-8', + 'format' => $this->pageFormat, + 'margin_left' => $margins["left"], + 'margin_right' => $margins["right"], + 'margin_top' => $margins["top"], + 'margin_bottom' => $margins["bottom"], + 'margin_header' => $margins["header"], + 'margin_footer' => $margins["footer"], + 'orientation' => $this->pageOrientation + ]; + } + + + /** * @throws InvalidStateException - * @return mPDF + * @return Mpdf */ public function getMPDF() { - if (!$this->mPDF instanceof mPDF) { - $margins = $this->getMargins(); - - $mpdf = new mPDF( - 'utf-8', // string $codepage - $this->pageFormat, // mixed $format - '', // float $default_font_size - '', // string $default_font - $margins["left"], // float $margin_left - $margins["right"], // float $margin_right - $margins["top"], // float $margin_top - $margins["bottom"], // float $margin_bottom - $margins["header"], // float $margin_header - $margins["footer"], // float $margin_footer - $this->pageOrientation - ); + if (!$this->mPDF instanceof Mpdf) { + + $mpdf = new Mpdf($this->getMPDFConfig()); + $mpdf->showImageErrors = true; $this->mPDF = $mpdf; @@ -580,7 +592,7 @@ public function save($dir, $filename = null) $filename = Strings::lower($filename ?: $this->documentTitle); if (Strings::endsWith($filename, ".pdf")) { - $filename = substr($filename, 0,-4); + $filename = substr($filename, 0, -4); } $filename = Strings::webalize($filename, "_") . ".pdf"; @@ -605,3 +617,4 @@ public function __toString() } } + diff --git a/tests/PdfResponse/expected/full.pdf b/tests/PdfResponse/expected/full.pdf index ea115ffd774913c8a47aa85d3737a9729b7bd45c..c3ede8d31c32adf4f0cf6fb572a654526ef1ef7a 100644 GIT binary patch delta 38 scmbPzmvR1G#tl2NIn5dL7z}{ec=O)u9wtWf$zFM0?B-mms;>TS0RFxUYXATM delta 34 qcmbP#mvQ!8#tl2NSTS0QrmyIRF3v delta 34 qcmbPwmvQ1<#trMTS)42GKvvU`{qjVAxi^

TQdM>JcLM