Skip to content

Commit d5ab2aa

Browse files
committed
Viewer
Commenting
1 parent 8053012 commit d5ab2aa

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/Viewer.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
*/
4242
class Viewer {
4343

44+
// the hive is where all data is stored, which is then usable from all template
45+
// files
4446
private static $hive = [];
4547

4648
/**
@@ -97,6 +99,8 @@ static private function render($file, $data){
9799
if(Sharer::get() !== null){
98100
extract(Sharer::get());
99101
}
102+
103+
// Merge data into the hive
100104
self::$hive = array_merge(self::$hive, get_defined_vars());
101105
unset($data);
102106

@@ -112,21 +116,27 @@ static private function render($file, $data){
112116
}
113117

114118
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
117121

118-
// else, return the value of the variable
122+
// else, assume it is a variable
119123
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
120126
list($object, $property) = explode('.', $matches[1]);
121127

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.
123130
if (strpos($property, '()') !== false) {
131+
// remove paranthesis
124132
list($function, $parenthesis) = explode('()', $property);
133+
134+
// return the callable method of the object from the hive
125135
return(self::$hive[$object]->$function());
126136
}else{
137+
// return the property of the object from the hive
127138
return(self::$hive[$object]->$property);
128139
}
129-
130140
}else{
131141
if(isset(self::$hive[$matches[1]])){
132142
return self::$hive[$matches[1]];

0 commit comments

Comments
 (0)