summaryrefslogtreecommitdiff
path: root/src/Renderer/Renderer.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2017-07-20 20:48:57 +0200
committerGitHub <noreply@github.com>2017-07-20 20:48:57 +0200
commit3406967ab4bf60fd00a22541a6b5a8155121cbad (patch)
treeab10822d61e7a2549be99bf2e7964351ddda484b /src/Renderer/Renderer.php
parent37d4edcd9ace5021b6eb02761a9c3865c5607f33 (diff)
parente1762e7764d4ee4f37757ecd2630f62a440dbf0e (diff)
Merge pull request #329 from MyIgel/renderer
Added renderer
Diffstat (limited to 'src/Renderer/Renderer.php')
-rw-r--r--src/Renderer/Renderer.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/Renderer/Renderer.php b/src/Renderer/Renderer.php
new file mode 100644
index 00000000..bf3d5609
--- /dev/null
+++ b/src/Renderer/Renderer.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Engelsystem\Renderer;
+
+use ErrorException;
+
+class Renderer
+{
+ /** @var self */
+ protected static $instance;
+
+ /** @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 &laquo;' . $template . '&raquo;.');
+ return '';
+ }
+
+ /**
+ * Add a new renderer engine
+ *
+ * @param EngineInterface $renderer
+ */
+ public function addRenderer(EngineInterface $renderer)
+ {
+ $this->renderer[] = $renderer;
+ }
+
+ /**
+ * @return self
+ * @throws ErrorException
+ */
+ public static function getInstance()
+ {
+ return self::$instance;
+ }
+
+ /**
+ * @param self $instance
+ */
+ public static function setInstance($instance)
+ {
+ self::$instance = $instance;
+ }
+}