Completed
Push — v4.0-dev ( b01e70...dabe54 )
by
unknown
01:56
created

Engine::createRenderTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace League\Plates;
4
5
/** API for the Plates system */
6
class Engine
7
{
8
    private $render;
9
    private $context;
10
11
    public function __construct(RenderTemplate $render = null) {
12
        $this->render = $render ?: self::createRenderTemplate();
13
        $this->context = [];
14
    }
15
16
    /** @return string */
17
    public function render($template_name, array $data) {
18
        $template = new Template($template_name, $data, [
19
            'engine' => $this,
20
        ]);
21
        return $this->render->renderTemplate($template);
22
    }
23
24
    public function addContext(array $context) {
25
        $this->context = array_merge($this->context, $context);
26
    }
27
28
    public function getContext() {
29
        return $this->context;
30
    }
31
32
    public static function createRenderTemplate() {
33
        $rt = new RenderTemplate\PlatesRenderTemplate();
34
        $rt = new RenderTemplate\LayoutRenderTemplate($rt);
35
        return $rt;
36
    }
37
}
38