Passed
Branch release (695ec7)
by Henry
04:31
created

TwigBuilder   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 11
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getBody() 0 7 1
1
<?php
2
/**
3
 * This file is part of the Divergence package.
4
 *
5
 * (c) Henry Paradiz <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Divergence\Responders;
11
12
use Divergence\App;
13
use Twig\Environment;
14
use Twig\Loader\FilesystemLoader;
15
use Psr\Http\Message\StreamInterface;
16
use Twig\Extension\StringLoaderExtension;
17
18
class TwigBuilder extends ResponseBuilder
19
{
20
    protected string $contentType = 'text/html; charset=utf-8';
21
22
    public function getBody(): StreamInterface
23
    {
24
        $loader = new FilesystemLoader([App::$App->ApplicationPath.'/views']);
25
        $env = new Environment($loader, ['strict_variables' => true]);
26
        $env->addExtension(new StringLoaderExtension());
27
        $output = $env->render($this->template, $this->data);
28
        return \GuzzleHttp\Psr7\stream_for($output);
29
    }
30
}
31