-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplate.php
More file actions
96 lines (72 loc) · 2.08 KB
/
Copy pathTemplate.php
File metadata and controls
96 lines (72 loc) · 2.08 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Onimla\HTML;
/**
* @property Element $html root element
* @property Head $head
* @property Element $body
*/
class Template extends Node {
/**
* Appears before root element
* @var string to be echoed
*/
public $doctype = '<!DOCTYPE html>';
public function __construct($children = FALSE) {
parent::__construct();
if (func_num_args() > 0) {
call_user_func_array(array($this, 'append'), func_get_args());
}
}
public function __toString() {
return implode(PHP_EOL, array($this->doctype, $this->html()));
}
public function __get($name) {
if (!isset($this->$name) AND method_exists($this, $name)) {
return call_user_func(array($this, $name));
}
return parent::__get($name);
}
public function html($instance = FALSE) {
if (!isset($this->html)) {
$this->html = new Element('html');
$this->html->append($this->head(), $this->body());
}
if ($instance === FALSE) {
return $this->html;
}
$this->html = $instance;
return $this;
}
/**
* @param Element $instance
* @return \Onimla\HTML\Template|\Onimla\HTML\Head
*/
public function head($instance = FALSE) {
if (!isset($this->head)) {
$this->head = new Head();
}
if ($instance === FALSE) {
return $this->head;
}
$this->head = $instance;
return $this;
}
public function title($text = FALSE) {
$this->head()->title($text);
return ($text === FALSE) ? $this->head()->title() : $this;
}
public function body($instance = FALSE) {
if (!isset($this->body)) {
$this->body = new Element('body');
}
if ($instance === FALSE) {
return $this->body;
}
$this->body = $instance;
return $this;
}
public function append($children) {
call_user_func_array(array($this->body(), __FUNCTION__), func_get_args());
return $this;
}
}