* For questions, help, comments, discussion, etc. please visit
 * https://github.com/CyberspaceNetworks/CoreSystem
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 */
include dirname(__FILE__) . "/../cnproject_config.php";
include dirname(__FILE__) . "/../cnautoload.php";
require_once dirname(__FILE__) . "/../cncore/web/includes/classes/CN.php";
require_once dirname(__FILE__) . "/../cncore/web/includes/classes/CNBootStrap.php";
require_once dirname(__FILE__) . "/../cncore/web/includes/classes/CNDispatcher.php";
require_once dirname(__FILE__) . "/../cncore/web/includes/classes/CNDownloadManager.php";
require_once dirname(__FILE__) . "/../cncore/api/CNProfiler/CNProfiler.php";
if (isset($_GET['profiler']) && $_GET['profiler'] == 1) {
    PA::$profiler = new PAProfiler();
    PA::$profiler->startTimer('PADispatcher');
}
$dispatcher = new PADispatcher($auto_load_list);
// User.php must be included after a new PADispatcher object is created
// otherwise the installation of CN breaks.
require_once getShadowedPath('api/CNUser/CNUser.php');
$script = $dispatcher->dispatch();
if (PA::$profiler) {
    PA::$profiler->stopTimer('PADispatcher');
}
if (PA::$profiler) {
    PA::$profiler->startTimer('Main Script', $script);
}
require_once $script;
if (PA::$profiler) {
    PA::$profiler->stopTimer('Main Script');
}
exit;
 /**
  * Determines the request type (php, or file) and dispatches control to the appropriate
  * classes and functions 
  */
 public function dispatch()
 {
     $res_script = null;
     list($file_type, $file_path, $success) = $this->parseRequestURL();
     if ($success) {
         switch ($file_type) {
             case 'php':
                 self::$request_type = 'script';
                 if (!($script = getShadowedPath($file_path))) {
                     out_error404(F_NOT_FOUND, $file_path);
                 }
                 if (!$this->current_route) {
                     $this->current_route = $_SERVER['PHP_SELF'];
                     $this->route_query_str = $_SERVER['QUERY_STRING'];
                 } else {
                     $this->route_query_str = $this->org_query_str;
                 }
                 $res_script = $this->bootApp($file_path);
                 break;
             default:
                 self::$request_type = 'file';
                 $download_manager = new PADownloadManager($file_path);
                 if (!$download_manager->getFile()) {
                     out_error404($download_manager->lastError(), $file_path);
                 }
                 exit;
         }
     } else {
         out_error404(F_NO_ROUTE);
     }
     return $res_script;
 }