From 829772c91613f7787ec6c0cdd68885b22679080a Mon Sep 17 00:00:00 2001 From: Fariz Luqman Date: Thu, 16 Feb 2017 05:43:17 +0800 Subject: [PATCH 1/2] Add class ss_exec_time --- src/Debugger.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Debugger.php b/src/Debugger.php index 9e3a1bd..137e355 100755 --- a/src/Debugger.php +++ b/src/Debugger.php @@ -187,7 +187,7 @@ static private function microtime_diff($start) * @since Method available since Release 0.1.0 */ static function exec_time(){ - echo ('Request takes '.(self::microtime_diff(SS_START) * 1000 ) . ' milliseconds'); + echo ('Request takes '.(self::microtime_diff(SS_START) * 1000 ) . ' milliseconds'); } static function startProfiling(){ From cc60becfdbee6afd4f911500f389a201a4cc8413 Mon Sep 17 00:00:00 2001 From: Fariz Luqman Date: Fri, 24 Feb 2017 14:04:55 +0800 Subject: [PATCH 2/2] Added templating engine --- src/Viewer.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Viewer.php b/src/Viewer.php index d4ce661..6088067 100755 --- a/src/Viewer.php +++ b/src/Viewer.php @@ -41,6 +41,8 @@ */ class Viewer { + private static $hive; + /** * Finds, renders and displays a template file. Reports a 404 error in * case of missing files. @@ -103,11 +105,23 @@ static private function render($file, &$data = []){ extract(Sharer::get()); } + // Get all defined vars into $hive, which is used in callback method replace + self::$hive = get_defined_vars(); + ob_start(); - include_once($file); - $output = ob_get_contents(); + include($file); + $input = ob_get_contents(); ob_end_clean(); - echo ($output); + + $output = preg_replace_callback('!\{\{(\w+)\}\}!', 'Viewer::replace', $input); + + echo($output); } + static private function replace($matches) { + if(isset(self::$hive[$matches[1]])){ + return self::$hive[$matches[1]]; + } + } + }