Passed
Pull Request — master (#17)
by Stephen
12:58 queued 10:30
created

PdfExportService::fromViewData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Sfneal\ViewExport\Pdf;
4
5
use Dompdf\Exception;
6
use Illuminate\Contracts\View\View;
7
use Sfneal\Actions\AbstractService;
8
use Sfneal\ViewExport\Pdf\Utils\PdfExporter;
9
10
class PdfExportService extends AbstractService
11
{
12
    // todo: add ability to pass urls to export
13
14
    /**
15
     * Provide a view to build the PDF from.
16
     *
17
     * @param View $view
18
     * @return PdfExporter
19
     * @throws Exception
20
     */
21
    public static function fromView(View $view): PdfExporter
22
    {
23
        return new PdfExporter($view);
24
    }
25
26
    /**
27
     * Create a view to build the PDF from.
28
     *
29
     * @param string $viewName
30
     * @param array $viewData
31
     * @return PdfExporter
32
     * @throws Exception
33
     */
34
    public static function fromViewData(string $viewName, array $viewData = []): PdfExporter
35
    {
36
        return new PdfExporter(view($viewName, $viewData));
37
    }
38
39
    /**
40
     * Provide an HTML string to build the PDF from.
41
     *
42
     * @param string $html
43
     * @return PdfExporter
44
     * @throws Exception
45
     */
46
    public static function fromHtml(string $html): PdfExporter
47
    {
48
        return new PdfExporter($html);
49
    }
50
51
    /**
52
     * Provide an HTML path to build the PDF from.
53
     *
54
     * @param string $path
55
     * @return PdfExporter
56
     * @throws Exception
57
     */
58
    public static function fromHtmlPath(string $path): PdfExporter
59
    {
60
        return new PdfExporter(file_get_contents($path));
61
    }
62
}
63