Total Complexity | 6 |
Total Lines | 29 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 2 |
1 | <?php |
||
14 | class RenderBlock |
||
15 | { |
||
16 | /** @var \Twig\Environment */ |
||
17 | private $twig; |
||
18 | |||
19 | public function __construct(\Twig\Environment $twig) |
||
20 | { |
||
21 | $this->twig = $twig; |
||
22 | } |
||
23 | |||
24 | public function render(Block $block, string $template, array $parameters = []): string |
||
25 | { |
||
26 | $blockId = $this->getNormalizedId($block); |
||
27 | $view = $this->twig->load($template); |
||
28 | if (false === $view->hasBlock($blockId)) { |
||
29 | throw new TemplateDoesNotContainBlock(); |
||
30 | } |
||
31 | |||
32 | $html = $view->renderBlock($blockId, $parameters); |
||
33 | if (empty($html) && false === $block->shouldRefresh()) { |
||
34 | throw new BlockIsEmpty(); |
||
35 | } |
||
36 | |||
37 | return $html; |
||
38 | } |
||
39 | |||
40 | private function getNormalizedId(Block $block): string |
||
43 | } |
||
44 | } |
||
45 |