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

PdfExportService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 6
c 1
b 0
f 0
dl 0
loc 63
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A fromView() 0 3 1
A fromHtml() 0 3 1
A fromViewData() 0 3 1
A fromHtmlPath() 0 3 1
A fromViewModel() 0 3 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