-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoxygen.class.php
74 lines (63 loc) · 2.2 KB
/
oxygen.class.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
<?
class Oxygen {
private static $stack = array();
private static $sp = 0;
public static function push($call){
self::$stack[self::$sp++] = $call;
}
public static function pop() {
return self::$stack[--self::$sp];
}
public static function open($tag = 'div', $data = array()){
if(is_array($tag)) {
$data = $tag;
$tag = 'div';
}
$call = self::$stack[self::$sp-1];
$data['remote'] = $call->instance->go() . '/';
$data['component'] = $call->name;
$call->stack[$call->sp++] = $tag;
echo '<' . $tag . ' class="' . self::getCssClass() . '"';
if(is_array($data)) {
foreach ($data as $key => $value) {
echo ' data-' . $key . '="' . htmlspecialchars(json_encode($value)) . '"';
}
}
echo '>';
}
public static function cssClassFor($class, $name) {
return 'css-' . $class . '-' . $name;
}
public static function close() {
$call = self::$stack[self::$sp-1];
$tag = $call->stack[--$call->sp];
echo '</' . $tag . '>';
}
public static function closeAll() {
$call = self::$stack[self::$sp-1];
while ($call->sp > 0) {
$tag = $call->stack[--$call->sp];
echo '</' . $tag . '>';
}
}
public static function getCssClass() {
if(self::$sp === 0) throw new Exception(
'getCssClass() call is valid only within template code'
);
$call = self::$stack[self::$sp-1];
if ($call->component === false) {
return $call->component = self::cssClassFor(
$call->class,
$call->name
);
} else {
return $call->component;
}
}
public static function Generate() {
$scope = Oxygen_Scope::root();
$generator = $scope->Oxygen_Generator();
$generator->generate();
}
}
?>