Ensure the resource manager exists when displaying an error message
[gitphp.git] / index.php
blob:a/index.php -> blob:b/index.php
<?php <?php
/** /**
* GitPHP * GitPHP
* *
* Index * Index
* *
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2010 Christopher Han * @copyright Copyright (c) 2010 Christopher Han
* @package GitPHP * @package GitPHP
*/ */
   
define('GITPHP_START_TIME', microtime(true)); define('GITPHP_START_TIME', microtime(true));
define('GITPHP_START_MEM', memory_get_usage()); define('GITPHP_START_MEM', memory_get_usage());
   
/** /**
* Define some paths * Define some paths
*/ */
define('GITPHP_BASEDIR', dirname(__FILE__) . '/'); define('GITPHP_BASEDIR', dirname(__FILE__) . '/');
define('GITPHP_CONFIGDIR', GITPHP_BASEDIR . 'config/'); define('GITPHP_CONFIGDIR', GITPHP_BASEDIR . 'config/');
define('GITPHP_INCLUDEDIR', GITPHP_BASEDIR . 'include/'); define('GITPHP_INCLUDEDIR', GITPHP_BASEDIR . 'include/');
define('GITPHP_GITOBJECTDIR', GITPHP_INCLUDEDIR . 'git/'); define('GITPHP_GITOBJECTDIR', GITPHP_INCLUDEDIR . 'git/');
define('GITPHP_CONTROLLERDIR', GITPHP_INCLUDEDIR . 'controller/'); define('GITPHP_CONTROLLERDIR', GITPHP_INCLUDEDIR . 'controller/');
define('GITPHP_RESOURCEDIR', GITPHP_INCLUDEDIR . 'resource/'); define('GITPHP_RESOURCEDIR', GITPHP_INCLUDEDIR . 'resource/');
define('GITPHP_LOCALEDIR', GITPHP_RESOURCEDIR . 'locale/'); define('GITPHP_LOCALEDIR', GITPHP_RESOURCEDIR . 'locale/');
   
include_once(GITPHP_INCLUDEDIR . 'version.php'); include_once(GITPHP_INCLUDEDIR . 'version.php');
   
require_once(GITPHP_INCLUDEDIR . 'Config.class.php'); require_once(GITPHP_INCLUDEDIR . 'Config.class.php');
   
require_once(GITPHP_RESOURCEDIR . 'Resource.class.php'); require_once(GITPHP_RESOURCEDIR . 'Resource.class.php');
   
require_once(GITPHP_INCLUDEDIR . 'Log.class.php'); require_once(GITPHP_INCLUDEDIR . 'Log.class.php');
   
require_once(GITPHP_GITOBJECTDIR . 'ProjectList.class.php'); require_once(GITPHP_GITOBJECTDIR . 'ProjectList.class.php');
   
require_once(GITPHP_INCLUDEDIR . 'MessageException.class.php'); require_once(GITPHP_INCLUDEDIR . 'MessageException.class.php');
   
require_once(GITPHP_CONTROLLERDIR . 'Controller.class.php'); require_once(GITPHP_CONTROLLERDIR . 'Controller.class.php');
   
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
   
try { try {
   
// Define these here because these get used in the config file // Define these here because these get used in the config file
define('GITPHP_COMPRESS_BZ2', 1); define('GITPHP_COMPRESS_BZ2', 1);
define('GITPHP_COMPRESS_GZ', 2); define('GITPHP_COMPRESS_GZ', 2);
define('GITPHP_COMPRESS_ZIP', 3); define('GITPHP_COMPRESS_ZIP', 3);
   
/* /*
* Configuration * Configuration
*/ */
GitPHP_Config::GetInstance()->LoadConfig(GITPHP_CONFIGDIR . 'gitphp.conf.php'); GitPHP_Config::GetInstance()->LoadConfig(GITPHP_CONFIGDIR . 'gitphp.conf.php');
   
/* /*
* Resource * Resource
*/ */
GitPHP_Resource::Instantiate(GitPHP_Config::GetInstance()->GetValue('locale', 'en_US')); GitPHP_Resource::Instantiate(GitPHP_Config::GetInstance()->GetValue('locale', 'en_US'));
   
/* /*
* Debug * Debug
*/ */
if (GitPHP_Log::GetInstance()->GetEnabled()) { if (GitPHP_Log::GetInstance()->GetEnabled()) {
GitPHP_Log::GetInstance()->SetStartTime(GITPHP_START_TIME); GitPHP_Log::GetInstance()->SetStartTime(GITPHP_START_TIME);
GitPHP_Log::GetInstance()->SetStartMemory(GITPHP_START_MEM); GitPHP_Log::GetInstance()->SetStartMemory(GITPHP_START_MEM);
} }
   
if (!GitPHP_Config::GetInstance()->GetValue('projectroot', null)) { if (!GitPHP_Config::GetInstance()->GetValue('projectroot', null)) {
throw new GitPHP_MessageException('A projectroot must be set in the config', true); throw new GitPHP_MessageException('A projectroot must be set in the config', true);
} }
   
/* /*
* Project list * Project list
*/ */
if (file_exists(GITPHP_CONFIGDIR . 'projects.conf.php')) { if (file_exists(GITPHP_CONFIGDIR . 'projects.conf.php')) {
GitPHP_ProjectList::Instantiate(GITPHP_CONFIGDIR . 'projects.conf.php', false); GitPHP_ProjectList::Instantiate(GITPHP_CONFIGDIR . 'projects.conf.php', false);
} else { } else {
GitPHP_ProjectList::Instantiate(GITPHP_CONFIGDIR . 'gitphp.conf.php', true); GitPHP_ProjectList::Instantiate(GITPHP_CONFIGDIR . 'gitphp.conf.php', true);
} }
   
$controller = GitPHP_Controller::GetController((isset($_GET['a']) ? $_GET['a'] : null)); $controller = GitPHP_Controller::GetController((isset($_GET['a']) ? $_GET['a'] : null));
if ($controller) { if ($controller) {
$controller->RenderHeaders(); $controller->RenderHeaders();
$controller->Render(); $controller->Render();
} }
   
} catch (Exception $e) { } catch (Exception $e) {
   
if (GitPHP_Config::GetInstance()->GetValue('debug', false)) { if (GitPHP_Config::GetInstance()->GetValue('debug', false)) {
throw $e; throw $e;
} }
   
  if (GitPHP_Resource::GetInstance() == null) {
  /*
  * In case an error was thrown before instantiating
  * the resource manager
  */
  GitPHP_Resource::Instantiate('en_US');
  }
   
require_once(GITPHP_CONTROLLERDIR . 'Controller_Message.class.php'); require_once(GITPHP_CONTROLLERDIR . 'Controller_Message.class.php');
$controller = new GitPHP_Controller_Message(); $controller = new GitPHP_Controller_Message();
$controller->SetParam('message', $e->getMessage()); $controller->SetParam('message', $e->getMessage());
if ($e instanceof GitPHP_MessageException) { if ($e instanceof GitPHP_MessageException) {
$controller->SetParam('error', $e->Error); $controller->SetParam('error', $e->Error);
} else { } else {
$controller->SetParam('error', true); $controller->SetParam('error', true);
} }
$controller->Render(); $controller->Render();
   
} }
   
if (GitPHP_Log::GetInstance()->GetEnabled()) { if (GitPHP_Log::GetInstance()->GetEnabled()) {
$entries = GitPHP_Log::GetInstance()->GetEntries(); $entries = GitPHP_Log::GetInstance()->GetEntries();
foreach ($entries as $logline) { foreach ($entries as $logline) {
echo "\n" . $logline; echo "\n" . $logline;
} }
} }
   
?> ?>
   
comments