PdfExporter   A
last analyzed

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\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