-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.php
More file actions
80 lines (66 loc) · 1.52 KB
/
view.php
File metadata and controls
80 lines (66 loc) · 1.52 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
class view {
private $template = '';
private $type = '';
private $data = array();
public function render($speed = false) {
if ($this->type == 'jade') {
echo $this->get();
} else {
if ($speed) {
echo speed::factory(config::factory('speed'), $this->get());
} else {
extract($this->data);
include $this->template;
}
}
}
public function get($speed = false) {
if ($this->type == 'jade') {
$jade = new Pug\Pug();
return $jade->render($this->template, $this->data);
} else {
ob_start();
$this->render();
if ($speed) {
return speed::factory(config::factory('speed'), ob_get_clean());
} else {
return ob_get_clean();
}
}
}
public function __toString() {
return $this->get();
}
public function view($template, $data = array()) {
global $dir;
$path = 'views';
$types = array(
'php',
'html',
'jade'
);
foreach ($types as $type) {
$include = $dir . '/' . $path . '/' . $template . '.' . $type;
if (file_exists($include)) {
$this->template = $include;
$this->type = $type;
break;
}
}
if (empty($this->template)) {
$type = 'jade';
$include = $include = $dir . '/' . $path . '/' . 'template' . '.' . $type;
file_put_contents($include, $template);
$this->template = $include;
$this->type = $type;
}
if ($data) {
$this->data = $data;
}
}
public static function factory($template, $data = array()) {
return new view($template, $data);
}
}
?>