Skip to content

Commit 241036d

Browse files
committed
Add docstrings
1 parent 6e3e19a commit 241036d

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

library/Pdfexport/ProvidedHook/Pdfexport.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
use RuntimeException;
2222
use Throwable;
2323

24+
/**
25+
* PDF Export Hook implementation that forwards the PDF generation to the first
26+
* supported PDF backend
27+
*/
2428
class Pdfexport extends PdfexportHook
2529
{
2630
protected ?BackendLocator $locator = null;
@@ -56,6 +60,7 @@ public static function first()
5660

5761
/**
5862
* Get the backend locator instance, creating it if necessary
63+
*
5964
* @return BackendLocator
6065
*/
6166
protected function getLocator(): BackendLocator
@@ -95,7 +100,9 @@ public function htmlToPdf($html)
95100
$locator = $this->getLocator();
96101
$backend = $locator->getFirstSupportedBackend();
97102
if ($backend === null) {
98-
Logger::warning("No supported PDF backend available.");
103+
Logger::warning('No supported PDF backend available.');
104+
105+
return null;
99106
}
100107

101108
$pdf = $backend->toPdf($document);
@@ -121,7 +128,15 @@ public function htmlToPdf($html)
121128
return $pdf;
122129
}
123130

124-
protected function emit(string $pdf, string $filename): void
131+
/**
132+
* Emit a PDF file as the response with the appropriate headers
133+
*
134+
* @param string $pdf The content of the PDF file to be emitted.
135+
* @param string $filename The filename to be used for the emitted PDF.
136+
*
137+
* @return never
138+
*/
139+
protected function emit(string $pdf, string $filename): never
125140
{
126141
/** @var Web $app */
127142
$app = Icinga::app();
@@ -132,6 +147,16 @@ protected function emit(string $pdf, string $filename): void
132147
->sendResponse();
133148
}
134149

150+
/**
151+
* Converts a ValidHtml object into a PrintableHtmlDocument instance
152+
*
153+
* If the provided ValidHtml is already an instance of PrintableHtmlDocument, it is returned as is.
154+
* Otherwise, a new PrintableHtmlDocument is created with the given HTML content.
155+
*
156+
* @param ValidHtml $html The HTML content to convert
157+
*
158+
* @return PrintableHtmlDocument
159+
*/
135160
protected function getPrintableHtmlDocument(ValidHtml $html): PrintableHtmlDocument
136161
{
137162
if ($html instanceof PrintableHtmlDocument) {
@@ -141,6 +166,13 @@ protected function getPrintableHtmlDocument(ValidHtml $html): PrintableHtmlDocum
141166
->setContent(HtmlString::create($html));
142167
}
143168

169+
/**
170+
* Merge multiple PDF files into a single one
171+
*
172+
* @param string ...$pdfs The paths to the PDF files to merge
173+
*
174+
* @return string the resulting PDF content
175+
*/
144176
protected function mergePdfs(string ...$pdfs): string
145177
{
146178
$merger = new PdfMerge();

0 commit comments

Comments
 (0)