summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid T. Sadler <davidtsadler@googlemail.com>2021-10-06 21:22:49 +0100
committerDavid T. Sadler <davidtsadler@googlemail.com>2021-10-06 21:22:49 +0100
commit245e2234eea0596b2f6aabcbf694e7fd6f458486 (patch)
treed7cca5f2f2a38744f29ebc75bedbbf9556689dc9 /src
parent82f4871c3ef07a821d18e217ca2aa5711de10105 (diff)
Implement template engine
Diffstat (limited to 'src')
-rw-r--r--src/DTS/Template.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/DTS/Template.php b/src/DTS/Template.php
new file mode 100644
index 0000000..89bd7f8
--- /dev/null
+++ b/src/DTS/Template.php
@@ -0,0 +1,32 @@
+<?php
+
+declare(strict_types=1);
+
+namespace DTS;
+
+class Template
+{
+ private string $path;
+
+ function __construct(string $path)
+ {
+ $this->path = $path;
+ }
+
+ public function render(string $template, array $data = []): string
+ {
+ $file = "{$this->path}$template.php";
+
+ if (!is_file($file) || !is_readable($file)) {
+ throw new \Exception("Unable to locate template $file");
+ }
+
+ extract($data);
+
+ ob_start();
+
+ require_once($file);
+
+ return ob_get_clean();
+ }
+}