TwigView::render()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lit\View\Twig;
6
7
use Lit\Air\Configurator as C;
8
use Lit\Voltage\AbstractView;
9
use Psr\Http\Message\ResponseInterface;
10
use Twig\Environment;
11
use Twig\TemplateWrapper;
12
13
class TwigView extends AbstractView
14
{
15
    /**
16
     * @var TemplateWrapper
17
     */
18
    protected $template;
19
20
    public function __construct(TemplateWrapper $template)
21
    {
22
        $this->template = $template;
23
    }
24
25
    public static function configuration($loader)
26
    {
27
        return [
28
            Environment::class => C::provideParameter([
29
                C::alias(Environment::class, 'loader'),
30
                C::alias(Environment::class, 'options'),
31
            ]),
32
            C::join(Environment::class, 'loader') => $loader,
33
        ];
34
    }
35
36
    public function render(array $data = []): ResponseInterface
37
    {
38
        $body = $this->getEmptyBody();
39
        $body->write($this->template->render($data));
40
41
        return $this->response;
42
    }
43
}
44