<?php
//error_reporting(E_ALL);

function getmicrotime() {
   list($usec, $sec) = explode(" ",microtime());
   return ((float)$usec + (float)$sec);
}

// $time_start = getmicrotime();
$gtfw_base_dir = @file_get_contents('config/gtfw_base_dir.def');
// does anyone know the regex for these two string replacements, so it can be executed once?
$gtfw_base_dir = str_replace('\\', '/', trim($gtfw_base_dir));
$gtfw_base_dir = preg_replace('/[\/]+$/', '', $gtfw_base_dir);

if (file_exists($gtfw_base_dir)) {
   define('GTFW_BASE_DIR', $gtfw_base_dir . '/');
   define('GTFW_APP_DIR', str_replace('\\', '/', dirname(__FILE__)) . '/');
   $gtfw_init_dir = GTFW_BASE_DIR . 'main/init/' . basename(__FILE__, '.php') . '/*.php';

   require_once 'main/function/SimpleBenchmark.class.php';
   ob_start();
   SimpleBenchmark::Instance()->start();
   foreach (glob($gtfw_init_dir) as $value) {
      require_once $value;
   }
   SimpleBenchmark::Instance()->stop();
   $return = ob_get_contents();
   ob_end_clean();
   # append Remote/Local Execution Time Memory (RETM)
   echo (substr($return,0,13) == '{"gtfwResult"')?substr_replace($return, ',"retm":'.json_encode(SimpleBenchmark::Instance()->result()).'}}', -2):$return;
} else {
   echo 'Fatal: Cannot find GTFW base!';
}

// $time_end = getmicrotime();
// $time = $time_end - $time_start;
// echo "Page rendered in $time seconds";
?>
