template.php (465B)
1 <?php 2 namespace Template; 3 final class Template { 4 private $data = array(); 5 6 public function set($key, $value) { 7 $this->data[$key] = $value; 8 } 9 10 public function render($template) { 11 $file = DIR_TEMPLATE . $template . '.tpl'; 12 13 if (is_file($file)) { 14 extract($this->data); 15 16 ob_start(); 17 18 require($file); 19 20 return ob_get_clean(); 21 } 22 23 throw new \Exception('Error: Could not load template ' . $file . '!'); 24 exit(); 25 } 26 }