Initial commit

This commit is contained in:
2019-10-19 02:06:23 +02:00
commit 994e0704a0
3 changed files with 54 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
/nbproject/
/vendor/
+17
View File
@@ -0,0 +1,17 @@
{
"name": "kavalanche/template",
"description": "Simple templating system",
"type": "library",
"authors": [
{
"name": "Wojtek",
"email": "w.lk@wp.pl"
}
],
"require": {},
"autoload": {
"psr-4": {
"Kavalanche\\Template\\": "src/"
}
}
}
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace Kavalanche\Template;
use Exception;
/**
* @author Wojciech Burda <w.lk@wp.pl>
*/
class View {
private $templateDirectory;
public function __construct($templateDirectory) {
$this->templateDirectory = $templateDirectory;
}
public function render($view, array $data, $base = null) {
extract($data);
if ($base) {
if (!file_exists($this->templateDirectory . '/' . $base . '.php')) {
throw new Exception('Base template not found!');
}
ob_start();
require $this->templateDirectory . '/' . $view . '.php';
$content = ob_get_clean();
require $this->templateDirectory . '/' . $base . '.php';
} else {
require $this->templateDirectory . '/' . $view . '.php';
}
}
}