-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplate.php
More file actions
37 lines (29 loc) · 782 Bytes
/
Template.php
File metadata and controls
37 lines (29 loc) · 782 Bytes
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
<?php
/**
* Template
* @author Gökhan Kaya <gkxdev@gmail.com>
*/
class Template {
private $dir;
private $data = [];
private $file;
public function __construct($dir = './templates/') {
if (!is_dir($dir)) {
if (!mkdir($dir, 0777, true)) {
throw new Exception('Failed to create template directory.');
}
}
$this->dir = $dir;
}
public function render($file, array $data = []) {
$this->file = $this->dir . $file . '.php';
if (!is_file($this->file)) {
throw new Exception('Could not load file: ' . $this->file);
}
extract($data);
ob_start();
include $this->file;
$buffer = ob_get_clean();
return $buffer;
}
}