Don't rethrow known exceptions
[gitphp.git] / index.php
blob:a/index.php -> blob:b/index.php
--- a/index.php
+++ b/index.php
@@ -8,13 +8,6 @@
  * @copyright Copyright (c) 2010 Christopher Han
  * @package GitPHP
  */
-
-/**
- * Use utf-8 encoding
- */
-if (function_exists('mb_internal_encoding')) {
-	mb_internal_encoding("UTF-8");
-}
 
 /**
  * Define start time / memory for benchmarking
@@ -34,29 +27,67 @@
 define('GITPHP_SMARTYDIR', GITPHP_LIBDIR . 'smarty/libs/');
 define('GITPHP_GESHIDIR', GITPHP_LIBDIR . 'geshi/');
 
+define('GITPHP_COMPRESS_TAR', 'tar');
+define('GITPHP_COMPRESS_BZ2', 'tbz2');
+define('GITPHP_COMPRESS_GZ', 'tgz');
+define('GITPHP_COMPRESS_ZIP', 'zip');
+
+/**
+ * Low level setup
+ */
+if (function_exists('mb_internal_encoding')) {
+	mb_internal_encoding("UTF-8");
+}
+date_default_timezone_set('UTC');
+
+/* 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);
+	}
+}
+
+if (!function_exists('mb_orig_substr')) {
+	function mb_orig_substr($str, $offset, $len = null)
+	{
+		return isset($len) ? substr($str, $offset, $len) : substr($str, $offset);
+	}
+}
+
+/**
+ * Version header
+ */
 include(GITPHP_INCLUDEDIR . 'version.php');
 
+/**
+ * Autoload setup
+ */
 require(GITPHP_INCLUDEDIR . 'AutoLoader.class.php');
-
 spl_autoload_register(array('GitPHP_AutoLoader', 'AutoLoad'));
 
-date_default_timezone_set('UTC');
+
+$router = new GitPHP_Router();
 
 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) {
 
-	$messageController = new GitPHP_Controller_Message();
+	$messageController = $router->GetMessageController();
+	$messageController->Initialize();
 
-	$config = $messageController->GetConfig();
-	if ($config && $config->GetValue('debug') && !($e instanceof GitPHP_MessageException)) {
-		throw $e;
+	if (!($e instanceof GitPHP_MessageException)) {
+		$config = $messageController->GetConfig();
+		if ($config && $config->GetValue('debug')) {
+			throw $e;
+		}
 	}
 
 	$messageController->SetParam('exception', $e);
@@ -67,18 +98,7 @@
 
 }
 
-if (isset($controller)) {
-	$log = $controller->GetLog();
-	if ($log && $log->GetEnabled()) {
-		$entries = $log->GetEntries();
-		foreach ($entries as $logline) {
-			echo "<br />\n" . htmlspecialchars($logline, ENT_QUOTES, 'UTF-8', true);
-		}
-		unset($logline);
-		unset($entries);
-	}
-	unset($controller);
-}
+unset($router);
 
 ?>
 

comments