Twig::render()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
1
<?php 
2
3
namespace Helmut\Forms\Engines;
4
5
use Helmut\Forms\Engine;
6
use Twig_Environment;
7
use Twig_Loader_Array;
8
9
class Twig implements Engine {
10
11
    /**
12
     * The twig compiler engine.
13
     *
14
     * @var \Twig_Environment
15
     */ 
16
    protected $compiler;
17
18
    /**
19
     * Fetch the compiler.
20
     *
21
     * @return \Twig_Environment
22
     */
23
    public function compiler()
24
    {
25
        if ( ! $this->compiler) {
26
            $this->compiler = new Twig_Environment(new Twig_Loader_Array([]));
27
        }
28
29
        return $this->compiler;
30
    }
31
32
    /**
33
     * Render the template content.
34
     *
35
     * @param  string  $path
36
     * @param  array  $properties
37
     * @return string
38
     */
39
    public function render($path, $properties = []) 
40
    {
41
        $content = file_get_contents($path);
42
43
        $template = $this->compiler()->createTemplate($content);
44
45
        return $template->render($properties);
46
    }
47
48
}
49