PdfExporter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 6
rs 10
c 6
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Sfneal\ViewExport\Pdf\Utils;
4
5
use Dompdf\Dompdf;
6
use Sfneal\ViewExport\Support\Adapters\Exporter;
7
use Sfneal\ViewExport\Support\Interfaces\Downloadable;
8
use Sfneal\ViewExport\Support\Interfaces\Viewable;
9
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
50
    {
51
        $this->pdf->stream($filename, ['Attachment' => true]);
52
    }
53
}
54