Completed
Pull Request — master (#1)
by Mathieu
04:21
created

PhpEngine::renderTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 2
1
<?php
2
3
namespace Charcoal\View\Php;
4
5
use \InvalidArgumentException;
6
7
// Intra-module (`charcoal-view`) depentencies
8
use \Charcoal\View\AbstractEngine;
9
10
/**
11
 *
12
 */
13
class PhpEngine extends AbstractEngine
14
{
15
    /**
16
     * @return string
17
     */
18
    public function type()
19
    {
20
        return 'php';
21
    }
22
23
    /**
24
     * @param string $templateString The template string to render.
25
     * @param mixed  $context        The rendering context.
26
     * @return string The rendered template string.
27
     */
28
    public function renderTemplate($templateString, $context)
29
    {
30
        // Prevents leaking global variable by forcing anonymous scope
31
        $render = function($templateString, $context) {
32
            extract($context);
33
            return eval('?>'.$templateString);
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
34
        };
35
36
        ob_start();
37
        $render($templateString, $context);
38
        $output = ob_get_clean();
39
40
        return $output;
41
    }
42
}
43