blob: ccda6881b6f5053b010f4ee4e4c9c17721b82a6a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<?php
namespace Engelsystem\Renderer;
use Psr\Log\LoggerAwareTrait;
class Renderer
{
use LoggerAwareTrait;
/** @var EngineInterface[] */
protected $renderer = [];
/**
* Render a template
*
* @param string $template
* @param mixed[] $data
* @return string
*/
public function render(string $template, array $data = []): string
{
foreach ($this->renderer as $renderer) {
if (!$renderer->canRender($template)) {
continue;
}
return $renderer->get($template, $data);
}
if ($this->logger) {
$this->logger->error('Unable to find a renderer for template file "{file}"', ['file' => $template]);
}
return '';
}
/**
* Add a new renderer engine
*
* @param EngineInterface $renderer
*/
public function addRenderer(EngineInterface $renderer): void
{
$this->renderer[] = $renderer;
}
}
|