TwigRenderer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 5 1
A __construct() 0 6 1
1
<?php
2
3
namespace kalanis\kw_table\output_twig;
4
5
6
use kalanis\kw_table\core\Table;
7
use Twig\Environment;
8
use Twig\Loader\ArrayLoader;
9
10
11
/**
12
 * Class TwigRenderer
13
 * @package kalanis\kw_table\output_direct
14
 * Direct renderer into Twig template (Symfony)
15
 */
16
class TwigRenderer extends Table\AOutput
17
{
18
    protected string $templatePath = '';
19
    protected ArrayLoader $loader;
20
    protected Environment $twig;
21
22
    public function __construct(Table $table)
23
    {
24
        parent::__construct($table);
25
        $this->templatePath = __DIR__ . '/../shared-templates/table.html.twig';
26
        $this->loader = new ArrayLoader();
27
        $this->twig = new Environment($this->loader);
28
    }
29
30
    public function render(): string
31
    {
32
        $source = strval(@file_get_contents($this->templatePath));
33
        $this->loader->setTemplate('kw_table', $source);
34
        return $this->twig->render('kw_table', ['table' => $this->table]);
35
    }
36
}
37