Completed
Push — master ( 047880...b09c02 )
by Kamil
92:08 queued 74:48
created

DelegatingTemplateEventRenderer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Bundle\UiBundle\Renderer;
15
16
use Sylius\Bundle\UiBundle\Registry\TemplateBlockRegistryInterface;
17
18
final class DelegatingTemplateEventRenderer implements TemplateEventRendererInterface
19
{
20
    /** @var TemplateBlockRegistryInterface */
21
    private $templateBlockRegistry;
22
23
    /** @var TemplateBlockRendererInterface */
24
    private $templateBlockRenderer;
25
26
    public function __construct(TemplateBlockRegistryInterface $templateBlockRegistry, TemplateBlockRendererInterface $templateBlockRenderer)
27
    {
28
        $this->templateBlockRegistry = $templateBlockRegistry;
29
        $this->templateBlockRenderer = $templateBlockRenderer;
30
    }
31
32
    public function render(string $eventName, array $context = []): string
33
    {
34
        $templateBlocks = $this->templateBlockRegistry->findEnabledForEvent($eventName);
35
        $renderedTemplates = [];
36
37
        foreach ($templateBlocks as $templateBlock) {
38
            $renderedTemplates[] = $this->templateBlockRenderer->render($eventName, $templateBlock, $context);
39
        }
40
41
        return implode("\n", $renderedTemplates);
42
    }
43
}
44