Skip to content

Commit

Permalink
Improve error reporting. Fix AKSW#29.
Browse files Browse the repository at this point in the history
  • Loading branch information
white-gecko committed May 31, 2013
1 parent 3329898 commit 0adb25f
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 35 deletions.
71 changes: 38 additions & 33 deletions classes/Xodx/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,56 @@ class Xodx_Application extends Saft_Application
public function run() {
parent::run();

// TODO: parse request uri to determine correct controller
try {
$bootstrap = $this->getBootstrap();

$bootstrap = $this->getBootstrap();
$appController = $this->getController('Xodx_ApplicationController');
$appController->authenticate();

$appController = $this->getController('Xodx_ApplicationController');
$appController->authenticate();
/**
* Prepare Template
*/
$this->_layout->setLayout('templates/layout.phtml');
$this->_layout->addMenu('templates/menu.phtml');

/**
* Prepare Template
*/
$this->_layout->setLayout('templates/layout.phtml');
$this->_layout->addMenu('templates/menu.phtml');
$request = $bootstrap->getResource('request');

$request = $bootstrap->getResource('request');
if ($request->hasValue('c')) {
$requestController = ucfirst(strtolower($request->getValue('c'))); // 'get'
} else {
$requestController = ucfirst(strtolower('index'));
}

if ($request->hasValue('c')) {
$requestController = ucfirst(strtolower($request->getValue('c'))); // 'get'
} else {
$requestController = ucfirst(strtolower('index'));
}

if ($request->hasValue('a')) {
$requestAction = strtolower($request->getValue('a'));
if ($request->hasValue('a')) {
$requestAction = strtolower($request->getValue('a'));

} else {
$requestAction = 'index';
}
} else {
$requestAction = 'index';
}

$controllerName = $this->_appNamespace . $requestController . 'Controller';
$controllerName = $this->_appNamespace . $requestController . 'Controller';

$actionName = $requestAction . 'Action';
$controller = $this->getController($controllerName);
$this->_layout = $controller->$actionName($this->_layout);
$actionName = $requestAction . 'Action';
$controller = $this->getController($controllerName);
$this->_layout = $controller->$actionName($this->_layout);

$userController = $this->getController('Xodx_UserController');
$user = $userController->getUser();
$userController = $this->getController('Xodx_UserController');
$user = $userController->getUser();

$this->_layout->username = $user->getName();
$this->_layout->notifications = $userController->getNotifications($user->getUri());
$this->_layout->username = $user->getName();
$this->_layout->notifications = $userController->getNotifications($user->getUri());

$config = $bootstrap->getResource('config');
if (isset($config['debug']) && $config['debug'] == false) {
$this->_layout->disableDebug();
$config = $bootstrap->getResource('config');
if (isset($config['debug']) && $config['debug'] == false) {
$this->_layout->disableDebug();
}
} catch (Exception $e) {
$this->_layout->setLayout('templates/errorlayout.phtml');
$this->_layout->errorType = 'Application Error';
$this->_layout->exception = $e;
$this->_layout->back = $this->getBaseUri();
$this->_layout->addContent('templates/error.phtml');
}

$this->_layout->render();
}
}
21 changes: 19 additions & 2 deletions templates/error.phtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
<h2>Error</h2>
<div class="error">
<?php if (isset($this->errorType)) : ?>
<h2><?= $this->errorType ?></h2>
<?php else : ?>
<h2>Error</h2>
<?php endif; ?>
<div class="alert alert-error">
<?php if (is_a($this->exception, 'Exception')): ?>
<strong><?= $this->exception->getMessage() ?></strong> in <?= basename($this->exception->getFile()) . '@l.' . $this->exception->getLine() ?>
<ol>
<?php foreach($this->exception->getTrace() as $item): ?>
<li><?=basename($item['file']) . '@l.' . $item['line'] ?></li>
<?php endforeach; ?>
</ol>
<?php else: ?>
<?= $this->exception ?>
<?php endif; ?>
</div>
<p>If you think reporting this error can help improving this software, please <a href="https://github.com/white-gecko/xodx/issues">create a new issue on our GitHub page</a>.</p>
<?php if (isset($this->back)) : ?>
<a class="btn" href="<?= $this->back ?>"><i class="icon-hand-left"></i> Back to Start</a>
<?php endif; ?>
55 changes: 55 additions & 0 deletions templates/errorlayout.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link type="text/css" href="resources/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link type="text/css" href="resources/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" />
<link type="text/css" href="resources/css/all.css" rel="stylesheet" />
<style type="text/css">
@media (min-width: 980px) {
body {
padding-top: 60px;
}
}
.sidebar-nav {
padding: 9px 0;
}
</style>
<script type="text/javascript" src="resources/jquery/jquery.js"></script>
<script type="text/javascript" src="resources/bootstrap/js/bootstrap.js"></script>
</head>
<body>
<div class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand"><img src="resources/img/xodx_20.png" alt="Xodx" title="[ˈɛksodʊs]" /></a>
</div>
</div>
</div>

<div class="container">
<?php
foreach ($this->_contentFiles as $contentFile) {
include $contentFile;
}
?>
</div>

<?php if ($this->_debug && !empty($this->_debugLog)) : ?>

<div class="debug" id="debugConsole">
<h3>Debuglog:</h3>
<pre>
<?= $this->_debugLog ?>
</pre>
</div>

<?php endif; ?>
</body>
</html>

0 comments on commit 0adb25f

Please sign in to comment.