Completed
Push — feature/sass-standard ( 649e69...554da1 )
by Vladimir
12:12
created

EvaluateFilter::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace BZIon\Twig;
4
5
/**
6
 * A Twig filter that takes a string Twig template and an array for context and renders it.
7
 *
8
 * i.e. A Twig filter to render Twig from inside of Twig
9
 */
10
class EvaluateFilter
11
{
12
    public function __invoke(\Twig_Environment $env, $string, array $context)
13
    {
14
        $template = $env->createTemplate($string);
15
16
        return $template->render($context);
17
    }
18
19
    public static function get()
20
    {
21
        return new \Twig_SimpleFilter('evaluate', new self(), [
22
            'needs_environment' => true,
23
            'is_safe' => [
24
                'evaluate' => true
25
            ]
26
        ]);
27
    }
28
}
29