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

TemplateEngine   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

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