PremailerEngine   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 78
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A get() 0 12 1
A getBaseEngine() 0 4 1
A getCompiler() 0 4 1
1
<?php namespace Luminaire\Premailer\Laravel;
2
3
/**
4
 * Created by Sublime Text 3
5
 *
6
 * @user     Kevin Tanjung
7
 * @website  http://kevintanjung.github.io
8
 * @email    [email protected]
9
 * @date     04/08/2016
10
 * @time     13:44
11
 */
12
13
use Illuminate\View\Engines\EngineInterface;
14
use Luminaire\Premailer\Laravel\PremailerCompiler;
15
use Luminaire\Premailer\HtmlString;
16
17
/**
18
 * The "Premailer" view engine class
19
 *
20
 * @package  \Luminaire\Premailer\Laravel
21
 */
22
class PremailerEngine implements EngineInterface
23
{
24
25
    /**
26
     * The underlying view engine instance
27
     *
28
     * @var \Illuminate\View\Engines\EngineInterface
29
     */
30
    protected $engine;
31
32
    /**
33
     * The "Premailer" compiler instance.
34
     *
35
     * @var \Illuminate\View\Compilers\CompilerInterface
36
     */
37
    protected $compiler;
38
39
    /**
40
     * A stack of the last compiled templates
41
     *
42
     * @var array
43
     */
44
    protected $compiled = [];
45
46
    /**
47
     * Create a new instance of "Premailer" view engine
48
     *
49
     * @param  \Illuminate\View\Engines\CompilerEngine         $engine
50
     * @param  \Luminaire\Premailer\Laravel\PremailerCompiler  $compiler [description]
51
     */
52
    public function __construct(EngineInterface $engine, PremailerCompiler $compiler)
53
    {
54
        $this->engine = $engine;
55
56
        $this->compiler = $compiler;
57
    }
58
59
    /**
60
     * Get the evaluated contents of the view.
61
     *
62
     * @param  string  $path
63
     * @param  array   $data
64
     * @return string
65
     */
66
    public function get($path, array $data = [])
67
    {
68
        // To preserve the capability of using any underlying templating system,
69
        // e.g. the Blade template or any templating engines that has already
70
        // been integrated to Illuminate View, Premailer will act as wrapper,
71
        // that will only inlined the CSS from the template system result.
72
        $result = $this->engine->get($path, $data);
73
74
        $premailer = new HtmlString($result);
75
76
        return $premailer->getHtml();
77
    }
78
79
    /**
80
     * Get the base engine instance
81
     *
82
     * @return \Illuminate\View\Engines\EngineInterface
83
     */
84
    public function getBaseEngine()
85
    {
86
        return $this->engine;
87
    }
88
89
    /**
90
     * Get the compiler implementation.
91
     *
92
     * @return \Illuminate\View\Compilers\CompilerInterface
93
     */
94
    public function getCompiler()
95
    {
96
        return $this->compiler;
97
    }
98
99
}
100