Comment out global exception catch temporarily to make development easier
[gitphp.git] / index.php
blob:a/index.php -> blob:b/index.php
--- a/index.php
+++ b/index.php
@@ -9,6 +9,9 @@
  * @package GitPHP
  */
 
+/**
+ * Define start time / memory for benchmarking
+ */
 define('GITPHP_START_TIME', microtime(true));
 define('GITPHP_START_MEM', memory_get_usage());
 
@@ -18,90 +21,84 @@
 define('GITPHP_BASEDIR', dirname(__FILE__) . '/');
 define('GITPHP_CONFIGDIR', GITPHP_BASEDIR . 'config/');
 define('GITPHP_INCLUDEDIR', GITPHP_BASEDIR . 'include/');
-define('GITPHP_GITOBJECTDIR', GITPHP_INCLUDEDIR . 'git/');
-define('GITPHP_CONTROLLERDIR', GITPHP_INCLUDEDIR . 'controller/');
+define('GITPHP_LOCALEDIR', GITPHP_BASEDIR . 'locale/');
+define('GITPHP_CACHEDIR', GITPHP_BASEDIR . 'cache/');
+define('GITPHP_LIBDIR', GITPHP_BASEDIR . 'lib/');
+define('GITPHP_SMARTYDIR', GITPHP_LIBDIR . 'smarty/libs/');
+define('GITPHP_GESHIDIR', GITPHP_LIBDIR . 'geshi/');
 
-/*
- * Version
+define('GITPHP_COMPRESS_TAR', 'tar');
+define('GITPHP_COMPRESS_BZ2', 'tbz2');
+define('GITPHP_COMPRESS_GZ', 'tgz');
+define('GITPHP_COMPRESS_ZIP', 'zip');
+
+/**
+ * Low level setup
  */
-include_once(GITPHP_INCLUDEDIR . 'version.php');
-
-/*
- * Constants
- */
-require_once(GITPHP_INCLUDEDIR . 'defs.constants.php');
-
-require_once(GITPHP_INCLUDEDIR . 'Config.class.php');
-
-require_once(GITPHP_INCLUDEDIR . 'Log.class.php');
-
-require_once(GITPHP_GITOBJECTDIR . 'ProjectList.class.php');
-
-require_once(GITPHP_INCLUDEDIR . 'MessageException.class.php');
-require_once(GITPHP_CONTROLLERDIR . 'Controller.class.php');
-
+if (function_exists('mb_internal_encoding')) {
+	mb_internal_encoding("UTF-8");
+}
 date_default_timezone_set('UTC');
 
-//try {
+/* strlen() can be overloaded in mbstring extension, so always using mb_orig_strlen for binary data */
+if (!function_exists('mb_orig_strlen')) {
+	function mb_orig_strlen($str)
+	{
+		return strlen($str);
+	}
+}
 
-	/*
-	 * Configuration
-	 */
-	try {
-		GitPHP_Config::GetInstance()->LoadConfig(GITPHP_CONFIGDIR . 'gitphp.conf.php.example');
-	} catch (Exception $e) {
+if (!function_exists('mb_orig_substr')) {
+	function mb_orig_substr($str, $offset, $len = null)
+	{
+		return isset($len) ? substr($str, $offset, $len) : substr($str, $offset);
 	}
-	GitPHP_Config::GetInstance()->LoadConfig(GITPHP_CONFIGDIR . 'gitphp.conf.php');
+}
 
-	/*
-	 * Debug
-	 */
-	if (GitPHP_Log::GetInstance()->GetEnabled()) {
-		GitPHP_Log::GetInstance()->SetStartTime(GITPHP_START_TIME);
-		GitPHP_Log::GetInstance()->SetStartMemory(GITPHP_START_MEM);
-	}
+/**
+ * Version header
+ */
+include(GITPHP_INCLUDEDIR . 'version.php');
 
-	/*
-	 * Project list
-	 */
-	GitPHP_ProjectList::Instantiate(GITPHP_CONFIGDIR . 'gitphp.conf.php');
+/**
+ * Autoload setup
+ */
+require(GITPHP_INCLUDEDIR . 'AutoLoader.class.php');
+spl_autoload_register(array('GitPHP_AutoLoader', 'AutoLoad'));
 
-	if (!GitPHP_Config::GetInstance()->GetValue('projectroot', null)) {
-		throw new GitPHP_MessageException('A projectroot must be set in the config', true);
-	}
 
-	$gitphp_current_project = null;
+$router = new GitPHP_Router();
 
-	if (isset($_GET['p'])) {
-		$gitphp_current_project = GitPHP_ProjectList::GetInstance()->GetProject(str_replace(chr(0), '', $_GET['p']));
-	}
+try {
 
-	$controller = GitPHP_Controller::GetController((isset($_GET['a']) ? $_GET['a'] : null));
+	$controller = $router->GetController();
 	if ($controller) {
+		$controller->Initialize();
 		$controller->RenderHeaders();
 		$controller->Render();
 	}
 
-//} catch (Exception $e) {
-//
-//	require_once(GITPHP_CONTROLLERDIR . 'Controller_Message.class.php');
-//	$controller = new GitPHP_Controller_Message();
-//	$controller->SetParam('message', $e->getMessage());
-//	if ($e instanceof GitPHP_MessageException) {
-//		$controller->SetParam('error', $e->Error);
-//	} else {
-//		$controller->SetParam('error', true);
-//	}
-//	$controller->Render();
-//
-//}
+} catch (Exception $e) {
 
-if (GitPHP_Log::GetInstance()->GetEnabled()) {
-	$entries = GitPHP_Log::GetInstance()->GetEntries();
-	foreach ($entries as $logline) {
-		echo "\n" . $logline;
+	$messageController = $router->GetMessageController();
+	$messageController->Initialize();
+
+	if (!($e instanceof GitPHP_MessageException)) {
+		$config = $messageController->GetConfig();
+		if ($config && $config->GetValue('debug')) {
+			throw $e;
+		}
 	}
+
+	$messageController->SetParam('exception', $e);
+	$messageController->RenderHeaders();
+	$messageController->Render();
+
+	unset($messageController);
+
 }
+
+unset($router);
 
 ?>
 

comments