MpdfRenderer   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 6
Bugs 1 Features 1
Metric Value
wmc 8
c 6
b 1
f 1
lcom 1
cbo 2
dl 0
loc 44
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getEngine() 0 8 2
A doRender() 0 4 1
A doPrepare() 0 17 3
A doRenderToString() 0 4 1
A doRenderToFile() 0 4 1
1
<?php
2
/**
3
 * Mpdf Renderer file
4
 *
5
 * @author     Leandro Silva <[email protected]>
6
 * @category   LosPdf
7
 * @license    https://github.com/Lansoweb/LosPdf/blob/master/LICENSE BSD-3 License
8
 * @link       http://github.com/LansoWeb/LosPdf
9
 */
10
namespace LosPdf\View\Renderer;
11
12
use mPDF;
13
use LosPdf\View\Model\PdfModel;
14
15
/**
16
 * Mpdf Renderer class
17
 *
18
 * @author     Leandro Silva <[email protected]>
19
 * @category   LosPdf
20
 * @license    https://github.com/Lansoweb/LosPdf/blob/master/LICENSE BSD-3 License
21
 * @link       http://github.com/LansoWeb/LosPdf
22
 */
23
final class MpdfRenderer extends AbstractRenderer
24
{
25
    public function getEngine()
26
    {
27
        if ($this->engine === null) {
28
            $this->engine = new mPDF();
29
        }
30
31
        return $this->engine;
32
    }
33
34
    protected function doRender()
35
    {
36
        return $this->getEngine()->Output();
37
    }
38
39
    protected function doPrepare($model, $values)
40
    {
41
        $this->html = $this->renderer->render($model, $values);
42
43
        $paperOrientation = $this->getOption(PdfModel::PAPER_ORIENTATION, PdfModel::ORIENTATION_PORTRAIT);
44
        $paperSize = $this->getOption(PdfModel::PAPER_SIZE, PdfModel::SIZE_A4);
45
46
        if (!is_array($paperSize)) {
47
            $format = strtolower($paperOrientation[0]);
48
            if ($format == 'l') {
49
                $paperSize = $paperSize.'-'.$format;
50
            }
51
        }
52
53
        $this->getEngine()->_setPageSize($paperSize, $paperOrientation);
54
        $this->getEngine()->WriteHTML($this->html);
55
    }
56
57
    protected function doRenderToString(PdfModel $model)
58
    {
59
        return $this->getEngine()->Output('', 'S');
60
    }
61
62
    protected function doRenderToFile(PdfModel $model, $fileName)
63
    {
64
        return $this->getEngine()->Output($fileName, 'F');
65
    }
66
}
67