Completed
Push — statistics_refactoring ( b2d9c2 )
by Luis
13:39
created

TemplateEngine::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Templates;
9
10
use Twig_Environment as Twig;
11
use Twig_Error_Loader as LoaderError;
12
use Twig_Error_Runtime as RuntimeError;
13
use Twig_Error_Syntax as SyntaxError;
14
use Twig_Loader_Filesystem as FileSystemLoader;
15
16
class TemplateEngine
17
{
18
    /** @var Twig */
19
    private $twig;
20
21
    public function __construct(Twig $twig = null)
22
    {
23
        $this->twig = $twig ?? new Twig(new FileSystemLoader(__DIR__ . '/../resources/templates'));
24
    }
25
26
    public function render($template, array $values): string
27
    {
28
        try {
29
            return $this->twig->render($template, $values);
30
        } catch (LoaderError | RuntimeError  | SyntaxError $e) {
31
            throw new TemplateFailure($e);
32
        }
33
    }
34
}
35