Passed
Push — master ( e0dcf6...69fb50 )
by Stephen
46s queued 10s
created

PdfExportService::fromViewModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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
use Sfneal\ViewModels\AbstractViewModel;
10
11
class PdfExportService extends AbstractService
12
{
13
    // todo: add ability to pass urls to export
14
15
    /**
16
     * Provide a view to build the PDF from.
17
     *
18
     * @param View $view
19
     * @return PdfExporter
20
     * @throws Exception
21
     */
22
    public static function fromView(View $view): PdfExporter
23
    {
24
        return new PdfExporter($view);
25
    }
26
27
    /**
28
     * Create a view to build the PDF from.
29
     *
30
     * @param string $viewName
31
     * @param array $viewData
32
     * @return PdfExporter
33
     * @throws Exception
34
     */
35
    public static function fromViewData(string $viewName, array $viewData = []): PdfExporter
36
    {
37
        return new PdfExporter(view($viewName, $viewData));
38
    }
39
40
    /**
41
     * Provide a view to build the PDF from.
42
     *
43
     * @param AbstractViewModel $viewModel
44
     * @return PdfExporter
45
     * @throws Exception
46
     */
47
    public static function fromViewModel(AbstractViewModel $viewModel): PdfExporter
48
    {
49
        return new PdfExporter($viewModel->renderNoCache());
50
    }
51
52
    /**
53
     * Provide an HTML string to build the PDF from.
54
     *
55
     * @param string $html
56
     * @return PdfExporter
57
     * @throws Exception
58
     */
59
    public static function fromHtml(string $html): PdfExporter
60
    {
61
        return new PdfExporter($html);
62
    }
63
64
    /**
65
     * Provide an HTML path to build the PDF from.
66
     *
67
     * @param string $path
68
     * @return PdfExporter
69
     * @throws Exception
70
     */
71
    public static function fromHtmlPath(string $path): PdfExporter
72
    {
73
        return new PdfExporter(file_get_contents($path));
74
    }
75
}
76