GridExtension::getFunctions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
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 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Twig\Extension;
6
7
use LAG\AdminBundle\Grid\Cell;
8
use LAG\AdminBundle\Grid\Grid;
9
use LAG\AdminBundle\Grid\View\CellRendererInterface;
10
use LAG\AdminBundle\Grid\View\GridRendererInterface;
11
use LAG\AdminBundle\Metadata\Operation;
12
use Twig\Extension\AbstractExtension;
13
use Twig\TwigFunction;
14
15
class GridExtension extends AbstractExtension
16
{
17
    public function __construct(
18
        private GridRendererInterface $gridRenderer,
19
        private CellRendererInterface $cellRenderer,
20
    ) {
21
    }
22
23
    public function getFunctions(): array
24
    {
25
        return [
26
            new TwigFunction('lag_admin_grid', [$this, 'renderGrid'], ['is_safe' => ['html']]),
27
            new TwigFunction('lag_admin_grid_cell', [$this, 'renderCell'], ['is_safe' => ['html']]),
28
        ];
29
    }
30
31
    public function renderGrid(Grid $grid, Operation $operation): string
32
    {
33
        return $this->gridRenderer->render($grid, $operation);
34
    }
35
36
    public function renderCell(Cell $cell): string
37
    {
38
        return $this->cellRenderer->render($cell);
39
    }
40
}
41