Total Complexity | 3 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 12 | ||
Bugs | 2 | Features | 0 |
1 | <?php |
||
9 | class PdfExporter extends Exporter implements Streamable |
||
10 | { |
||
11 | /** |
||
12 | * @var Dompdf |
||
13 | */ |
||
14 | private $pdf; |
||
15 | |||
16 | /** |
||
17 | * Exporter constructor. |
||
18 | * |
||
19 | * - $content can be a View or HTML file contents |
||
20 | * |
||
21 | * @param Dompdf $pdf |
||
22 | */ |
||
23 | public function __construct(Dompdf $pdf) |
||
24 | { |
||
25 | $this->pdf = $pdf; |
||
26 | |||
27 | // Store output to a property to avoid retrieving twice |
||
28 | $this->output = $this->pdf->output(); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * View the PDF in the clients browser. |
||
33 | * |
||
34 | * @param string $filename |
||
35 | * @return void |
||
36 | */ |
||
37 | public function view(string $filename = 'output.pdf'): void |
||
38 | { |
||
39 | $this->pdf->stream($filename, ['Attachment' => false]); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Download the PDF using the clients browser. |
||
44 | * |
||
45 | * @param string $filename |
||
46 | * @return void |
||
47 | */ |
||
48 | public function download(string $filename = 'output.pdf'): void |
||
51 | } |
||
52 | } |
||
53 |