1
1
<?php
2
2
/**
3
- * DOMPdf generator class
4
- *
5
3
* @section LICENSE
6
4
* This file is created by vianetz <[email protected] >.
7
5
* The code is distributed under the GPL license.
@@ -33,16 +31,10 @@ final class Dompdf extends AbstractGenerator
33
31
{
34
32
private const TOTAL_PAGE_COUNT_PLACEHOLDER = '__PDF_TPC__ ' ;
35
33
36
- /** @var \Dompdf\Dompdf */
37
- private $ domPdf ;
34
+ private \Dompdf \Dompdf $ domPdf ;
38
35
39
- /**
40
- * Render the pdf document.
41
- *
42
- * @return string|null
43
- * @throws \Exception
44
- */
45
- public function renderPdfDocument (DocumentInterface $ documentModel )
36
+ /** @throws \Exception */
37
+ public function renderPdfDocument (DocumentInterface $ documentModel ): ?string
46
38
{
47
39
$ this ->initPdf ();
48
40
@@ -54,12 +46,7 @@ public function renderPdfDocument(DocumentInterface $documentModel)
54
46
return $ this ->domPdf ->output ();
55
47
}
56
48
57
- /**
58
- * Init PDF default settings.
59
- *
60
- * @return Dompdf
61
- */
62
- protected function initPdf ()
49
+ protected function initPdf (): self
63
50
{
64
51
$ this ->domPdf = new \Dompdf \Dompdf ($ this ->getDompdfOptions ());
65
52
@@ -91,23 +78,23 @@ protected function getHtmlContentsForDocument(DocumentInterface $documentModel):
91
78
*
92
79
* @return array<string,mixed>
93
80
*/
94
- private function getDompdfOptions ()
81
+ private function getDompdfOptions (): array
95
82
{
96
- return array (
83
+ return [
97
84
'isPhpEnabled ' => true ,
98
85
'isRemoteEnabled ' => true ,
99
86
'chroot ' => $ this ->config ->getChrootDir (),
100
- ) ;
87
+ ] ;
101
88
}
102
89
103
90
private function injectPageCount (): void
104
91
{
105
92
$ canvas = $ this ->domPdf ->getCanvas ();
106
- $ pdf = $ canvas ->get_cpdf ();
93
+ $ pdf = $ canvas ->get_cpdf (); // @phpstan-ignore-line
107
94
108
95
foreach ($ pdf ->objects as &$ o ) {
109
96
if ($ o ['t ' ] === 'contents ' ) {
110
- $ o ['c ' ] = str_replace (self ::TOTAL_PAGE_COUNT_PLACEHOLDER , $ canvas ->get_page_count (), $ o ['c ' ]);
97
+ $ o ['c ' ] = str_replace (self ::TOTAL_PAGE_COUNT_PLACEHOLDER , ( string ) $ canvas ->get_page_count (), $ o ['c ' ]);
111
98
}
112
99
}
113
100
}
0 commit comments