41
41
*/
42
42
class Viewer {
43
43
44
+ // the hive is where all data is stored, which is then usable from all template
45
+ // files
44
46
private static $ hive = [];
45
47
46
48
/**
@@ -97,6 +99,8 @@ static private function render($file, $data){
97
99
if (Sharer::get () !== null ){
98
100
extract (Sharer::get ());
99
101
}
102
+
103
+ // Merge data into the hive
100
104
self ::$ hive = array_merge (self ::$ hive , get_defined_vars ());
101
105
unset($ data );
102
106
@@ -112,21 +116,27 @@ static private function render($file, $data){
112
116
}
113
117
114
118
static private function replace ($ matches ) {
115
- // !TODO if '.' is found in the string , assume it is an object
116
- // and return the property of the object
119
+ // If '.' is found in the $matches[1] , assume it is an object
120
+ // which have a property
117
121
118
- // else, return the value of the variable
122
+ // else, assume it is a variable
119
123
if (strpos ($ matches [1 ], '. ' ) !== false ) {
124
+ // explode the part before and after '.'
125
+ // the part before '.' is an object, while the part after '.' is a property
120
126
list ($ object , $ property ) = explode ('. ' , $ matches [1 ]);
121
127
122
- // if a '()' is found in $property, change it to callable
128
+ // if a '()' is found in $property, we will then assume it to be a callable
129
+ // method.
123
130
if (strpos ($ property , '() ' ) !== false ) {
131
+ // remove paranthesis
124
132
list ($ function , $ parenthesis ) = explode ('() ' , $ property );
133
+
134
+ // return the callable method of the object from the hive
125
135
return (self ::$ hive [$ object ]->$ function ());
126
136
}else {
137
+ // return the property of the object from the hive
127
138
return (self ::$ hive [$ object ]->$ property );
128
139
}
129
-
130
140
}else {
131
141
if (isset (self ::$ hive [$ matches [1 ]])){
132
142
return self ::$ hive [$ matches [1 ]];
0 commit comments