Passed
Push — master ( c67edb...a841dd )
by Stephen
01:37 queued 11s
created

PdfExporter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 12
Bugs 2 Features 0
Metric Value
eloc 6
c 12
b 2
f 0
dl 0
loc 42
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A download() 0 3 1
A view() 0 3 1
A __construct() 0 6 1
1
<?php
2
3
namespace Sfneal\ViewExport\Pdf\Utils;
4
5
use Dompdf\Dompdf;
6
use Sfneal\ViewExport\Support\Exporter;
7
use Sfneal\ViewExport\Support\Streamable;
8
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
49
    {
50
        $this->pdf->stream($filename, ['Attachment' => true]);
51
    }
52
}
53