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

Engine   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 4
Bugs 0 Features 0
Metric Value
dl 0
loc 32
rs 10
c 4
b 0
f 0
wmc 6
lcom 2
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A render() 0 6 1
A addContext() 0 3 1
A getContext() 0 3 1
A createRenderTemplate() 0 5 1
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