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