-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
83 lines (72 loc) · 1.5 KB
/
view.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
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
81
82
83
<?php
class Scaffold_View
{
protected $_path = './views';
protected $_file = null;
protected $_data = array();
public function __construct($name = null, $data = null)
{
$this->SetFile($name);
$this->SetData($data);
}
public static function Factory($name = null, $data = null)
{
return new Scaffold_View($name, $data);
}
public function Render()
{
// Start capturing the output
ob_start();
if (isset($this->_file))
{
// Import variables into the namespace
extract($this->_data, EXTR_SKIP);
// Include the view, allow access to class instance
include $this->_file;
}
// Dump the buffer and return the output
return ob_get_clean();
}
public function Escape($value)
{
return htmlentities(stripslashes($value));
}
// Chainable
public function SetData($data)
{
if (is_array($data) AND ! empty($data))
$this->_data = array_merge($this->_data, $data);
return $this;
}
// Chainable
public function SetPath($path)
{
if (is_string($path) AND is_dir($path))
$this->_path = $path;
return $this;
}
// Chainable
public function SetFile($basename)
{
if (is_string($basename))
{
$file = $this->_path.DIRECTORY_SEPARATOR.$basename;
if (is_file($file) AND is_readable($file))
$this->_file = $file;
}
return $this;
}
public function __toString()
{
return $this->Render();
}
public function __set($key, $value)
{
$this->_data[$key] = $value;
}
public function __get($key)
{
if (isset($this->_data[$key]))
return $this->_data[$key];
}
}