Skip to content

Commit 9c8f83f

Browse files
authored
Merge pull request #4649 from oleibman/mpdford
Temporary Workaround for Mpdf Php8.5 Deprecation
2 parents c8a1a5f + a76c9b8 commit 9c8f83f

File tree

4 files changed

+40
-26
lines changed

4 files changed

+40
-26
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@
9292
"dealerdirect/phpcodesniffer-composer-installer": "dev-main",
9393
"dompdf/dompdf": "^2.0 || ^3.0",
9494
"friendsofphp/php-cs-fixer": "^3.2",
95-
"mitoteam/jpgraph": "^10.3",
95+
"mitoteam/jpgraph": "^10.3 || 10.5.0-beta",
9696
"mpdf/mpdf": "^8.1.1",
9797
"phpcompatibility/php-compatibility": "^9.3",
9898
"phpstan/phpstan": "^1.1 || ^2.0",
99-
"phpstan/phpstan-phpunit": "^1.0 || ^2.0",
10099
"phpstan/phpstan-deprecation-rules": "^1.0 || ^2.0",
100+
"phpstan/phpstan-phpunit": "^1.0 || ^2.0",
101101
"phpunit/phpunit": "^10.5",
102102
"squizlabs/php_codesniffer": "^3.7",
103103
"tecnickcom/tcpdf": "^6.5"

composer.lock

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PhpSpreadsheet/Writer/Pdf/Mpdf.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ public function save($filename, int $flags = 0): void
4040

4141
// Create PDF
4242
$config = ['tempDir' => $this->tempDir . '/mpdf'];
43+
$restoreHandler = false;
44+
if (PHP_VERSION_ID >= self::$temporaryVersionCheck) {
45+
// @codeCoverageIgnoreStart
46+
set_error_handler(self::specialErrorHandler(...));
47+
$restoreHandler = true;
48+
// @codeCoverageIgnoreEnd
49+
}
4350
$pdf = $this->createExternalWriterInstance($config);
4451
$ortmp = $orientation;
4552
$pdf->_setPageSize($paperSize, $ortmp);
@@ -83,9 +90,30 @@ public function save($filename, int $flags = 0): void
8390
$str = $pdf->Output('', 'S');
8491
fwrite($fileHandle, $str);
8592

93+
if ($restoreHandler) {
94+
restore_error_handler(); // @codeCoverageIgnore
95+
}
8696
parent::restoreStateAfterSave();
8797
}
8898

99+
protected static int $temporaryVersionCheck = 80500;
100+
101+
/**
102+
* Temporary handler for Php8.5 waiting for Dompdf release.
103+
*
104+
* @codeCoverageIgnore
105+
*/
106+
public function specialErrorHandler(int $errno, string $errstr, string $filename, int $lineno): bool
107+
{
108+
if ($errno === E_DEPRECATED) {
109+
if (preg_match('/Providing an empty string is deprecated/', $errstr) === 1) {
110+
return true;
111+
}
112+
}
113+
114+
return false; // continue error handling
115+
}
116+
89117
/**
90118
* Convert inches to mm.
91119
*/

tests/bootstrap.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
function phpunit10ErrorHandler(int $errno, string $errstr, string $filename, int $lineno): bool
88
{
9-
if (strIncrement85(PHP_VERSION_ID, $errno, $errstr, $filename)) {
10-
return true; // message suppressed - stop error handling
11-
}
129
$x = error_reporting() & $errno;
1310
if (
1411
in_array(
@@ -34,18 +31,6 @@ function phpunit10ErrorHandler(int $errno, string $errstr, string $filename, int
3431
return false; // continue error handling
3532
}
3633

37-
function strIncrement85(int $version, int $errno, string $errstr, string $filename): bool
38-
{
39-
if ($version < 80500 || $errno !== E_DEPRECATED) {
40-
return false;
41-
}
42-
if (preg_match('/canonical/', $errstr) === 1 && preg_match('/mitoteam/', $filename) === 1) {
43-
return true;
44-
}
45-
46-
return false;
47-
}
48-
4934
if (!method_exists(PHPUnit\Framework\TestCase::class, 'setOutputCallback')) {
5035
set_error_handler('phpunit10ErrorHandler');
5136
}

0 commit comments

Comments
 (0)