summaryrefslogtreecommitdiff
path: root/src/Renderer/Renderer.php
blob: 5ed7cf31cf0f2ec7e7b9060d2a8ae1c596906988 (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
<?php

namespace Engelsystem\Renderer;

class Renderer
{
    /** @var EngineInterface[] */
    protected $renderer = [];

    /**
     * Render a template
     *
     * @param string  $template
     * @param mixed[] $data
     * @return string
     */
    public function render($template, $data = [])
    {
        foreach ($this->renderer as $renderer) {
            if (!$renderer->canRender($template)) {
                continue;
            }

            return $renderer->get($template, $data);
        }

        engelsystem_error('Unable to find a renderer for template file "' . $template . '".');
        return '';
    }

    /**
     * Add a new renderer engine
     *
     * @param EngineInterface $renderer
     */
    public function addRenderer(EngineInterface $renderer)
    {
        $this->renderer[] = $renderer;
    }
}