1
1
<?php
2
+ declare (strict_types=1 );
3
+
2
4
/**
3
5
* Vianetz Public Pdf Model
4
6
*
29
31
30
32
class Pdf implements PdfInterface
31
33
{
32
- /**
33
- * The generator instance.
34
- *
35
- * @var GeneratorInterface
36
- */
37
- private $ generator ;
38
-
39
- /** @var \Vianetz\Pdf\Model\PdfMerge */
40
- private $ pdfMerge ;
41
-
42
- /**
43
- * The (cached) pdf contents.
44
- *
45
- * @var string|null
46
- */
47
- private $ contents ;
34
+ private GeneratorInterface $ generator ;
35
+ private PdfMerge $ pdfMerge ;
36
+ private ?string $ contents = null ;
48
37
49
38
/**
50
39
* Initialize empty array for PDF documents to print.
51
40
*
52
- * @var array<\Vianetz\Pdf\Model\DocumentInterface |\Vianetz\Pdf\Model\PdfDocumentInterface>
41
+ * @var array<\Vianetz\Pdf\Model\HtmlDocumentInterface |\Vianetz\Pdf\Model\PdfDocumentInterface>
53
42
*/
54
- private $ documents = [];
43
+ private array $ documents = [];
55
44
56
- /** @var Config */
57
- protected $ config ;
58
-
59
- /** @var \Vianetz\Pdf\Model\EventManagerInterface */
60
- protected $ eventManager ;
45
+ protected Config $ config ;
46
+ protected EventManagerInterface $ eventManager ;
61
47
62
48
/**
63
49
* Default constructor initializes pdf generator.
@@ -76,10 +62,8 @@ final public function __construct(
76
62
$ this ->eventManager = $ eventManager ;
77
63
}
78
64
79
- /**
80
- * {@inheritDoc}
81
- */
82
- final public function getContents ()
65
+ /** {@inheritDoc} */
66
+ final public function getContents (): string
83
67
{
84
68
if ($ this ->contents === null ) {
85
69
$ this ->renderPdfContentsForAllDocuments ();
@@ -89,10 +73,8 @@ final public function getContents()
89
73
return $ this ->contents ;
90
74
}
91
75
92
- /**
93
- * {@inheritDoc}
94
- */
95
- final public function saveToFile ($ fileName )
76
+ /** {@inheritDoc} */
77
+ final public function saveToFile (string $ fileName ): bool
96
78
{
97
79
$ pdfContents = $ this ->getContents ();
98
80
@@ -102,7 +84,7 @@ final public function saveToFile($fileName)
102
84
/**
103
85
* Add a new document to generate.
104
86
*
105
- * @param \Vianetz\Pdf\Model\DocumentInterface |\Vianetz\Pdf\Model\PdfDocumentInterface $documentModel
87
+ * @param \Vianetz\Pdf\Model\HtmlDocumentInterface |\Vianetz\Pdf\Model\PdfDocumentInterface $documentModel
106
88
*
107
89
* @api
108
90
*/
@@ -117,10 +99,8 @@ final public function addDocument($documentModel): self
117
99
118
100
/**
119
101
* Returns the number of documents added to the generator.
120
- *
121
- * @return int
122
102
*/
123
- final public function countDocuments ()
103
+ final public function countDocuments (): int
124
104
{
125
105
return count ($ this ->documents );
126
106
}
@@ -131,35 +111,29 @@ final public function countDocuments()
131
111
* Note:
132
112
* This method only exists for compatibility reasons to provide the same interface as the original Zend_Pdf
133
113
* components.
134
- *
135
- * @return string
136
114
*/
137
- final public function render ()
115
+ final public function render (): string
138
116
{
139
117
return $ this ->getContents ();
140
118
}
141
119
142
- /**
143
- * @return \Vianetz\Pdf\Model\Config
144
- */
145
- public function getConfig ()
120
+ public function getConfig (): Config
146
121
{
147
122
return $ this ->config ;
148
123
}
149
124
150
125
/**
151
126
* Return merged pdf contents of all documents and save it to single temporary files.
152
127
*
153
- * @return void
154
128
* @throws \Vianetz\Pdf\NoDataException
155
129
*/
156
- private function renderPdfContentsForAllDocuments ()
130
+ private function renderPdfContentsForAllDocuments (): void
157
131
{
158
132
$ hasData = false ;
159
133
foreach ($ this ->documents as $ documentInstance ) {
160
134
$ this ->eventManager ->dispatch ('vianetz_pdf_document_render_before ' , ['document ' => $ documentInstance ]);
161
135
162
- if ($ documentInstance instanceof DocumentInterface ) {
136
+ if ($ documentInstance instanceof HtmlDocumentInterface ) {
163
137
$ this ->eventManager ->dispatch ('vianetz_pdf_ ' . $ documentInstance ->getDocumentType () . '_document_render_before ' , ['document ' => $ documentInstance ]);
164
138
165
139
$ pdfContents = $ this ->generator ->renderPdfDocument ($ documentInstance );
0 commit comments