-
Notifications
You must be signed in to change notification settings - Fork 3
/
Template.php
54 lines (40 loc) · 936 Bytes
/
Template.php
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php namespace TooBasic;
class Template
{
protected $_file;
public function __construct($file = null)
{
$this->_file = $file;
}
public function getWrapped()
{
$wrapped = $this->get('_wrapper');
$wrapped->content = $this;
return $wrapped;
}
public function get($file)
{
$tpl = clone $this;
$tpl->_file = $file;
return $tpl;
}
public static function show($file, array $variables = array())
{
$tpl = new self($file);
foreach ($variables as $key => $value)
$tpl->$key = $value;
print $tpl->getWrapped();
}
public function __call($name, $arguments)
{
if (isset($this->$name) && $this->$name instanceof \Closure)
return $this->$name->__invoke(...$arguments);
throw new Exception('Call to undefined method Template::'.$name.'()');
}
public function __toString()
{
ob_start();
require('tpl/'. $this->_file .'.php');
return str_replace(["\t", "\n"], '', ob_get_clean());
}
}