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

TwigBuilder::getBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
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