<?php

/********************************************************************
*                                                                   *
*   LICENSE: This file is subject to project "MoHAAS.NET".          *
*   That project is not open source. Its content belongs to the     *
*   community MoHAAS.NET. Any distribution and usage of this        *
*   software or parts of its code is forbidden.                     *
*                                                                   *
*   @name           MoHAAS.NET                                      *
*   @author         Andreas                                         *
*   @copyright      MoHAAS.NET                                      *
*   @date           08.05.2014                                      *
*   @website        http://www.mohaas.net                           *
*                                                                   *
*   Copyright (C) Andreas, MoHAAS.NET                               *
*                                                                   *
********************************************************************/


namespace MohaasNet;


// Define start time
define('PHP_SCRIPT_START', microtime(true));

// Set up reporting errors
if (isset($_GET['debug'])) {
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
} else {
    ini_set('display_errors', 0);
    error_reporting(0);
    mysqli_report(MYSQLI_REPORT_OFF);
}

// Autoload class files
spl_autoload_register(function($className) {
    $className = ltrim($className, '\\');
    $fileName  = '../web/php' . DIRECTORY_SEPARATOR;
    $namespace = '';
    if ($lastNsPos = strrpos($className, '\\')) {
        $namespace = substr($className, 0, $lastNsPos);
        $className = substr($className, $lastNsPos + 1);
        $fileName .= str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
    }
    $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
    if (file_exists($fileName)) {
		require $fileName;
	}
});

// Switch access states
new Controller_Desktop();

?>