Various error-handling changes

This commit is contained in:
Timothy Warren 2012-01-03 21:54:09 -05:00
parent e19814fdfa
commit df35da10bb
4 changed files with 59 additions and 47 deletions

View File

@ -4,6 +4,7 @@
error_reporting(-1);
// Set the default paths
define('BASE_PATH', __DIR__);
define('SYS_PATH', __DIR__.'/sys/');
define('MOD_PATH', __DIR__.'/modules/');
define('APP_PATH', __DIR__.'/app/');

View File

@ -4,6 +4,34 @@
* File including common framework-wide functions
*/
/**
* Function to run on script shutdown
* -used to catch most fatal errors, and
* display them cleanly
*/
function shutdown()
{
// Catch the last error
$error = error_get_last();
// types of errors that are fatal
$fatal = array(E_ERROR, E_PARSE, E_RECOVERABLE_ERROR);
// Display pretty error page
if(in_array($error['type'], $fatal))
{
$file = str_replace(BASE_PATH, "", $error['file']);
$err_msg = <<<TXT
<h2>Fatal Error: </h2>
{$error['message']}<br /><br />
<strong>File:</strong> {$file}<br /><br />
<strong>Line:</strong> {$error['line']}
TXT;
show_error($err_msg);
}
}
/**
* Function to search through the tree to find the necessary file
*
@ -56,7 +84,11 @@ function on_error($severity, $message, $filepath, $line, $context)
E_USER_NOTICE => 'User Notice',
E_STRICT => 'Strict Error'
);
//Make it prettier
$message = highlight_string($message, TRUE);
$filepath = str_replace(BASE_PATH, "", $filepath);
$severity = (isset($levels[$severity])) ? $levels[$severity] : $severity;
// Contain the content for buffering
@ -72,7 +104,7 @@ function on_error($severity, $message, $filepath, $line, $context)
// --------------------------------------------------------------------------
/**
* Custom exception handler
* Custom exception handlererror_get_last
*/
function on_exception($exception)
{
@ -350,6 +382,7 @@ function do_curl($url, $options=array())
// --------------------------------------------------------------------------
//Set error handlers
register_shutdown_function('shutdown');
set_error_handler('on_error');
set_exception_handler('on_exception');
@ -362,4 +395,4 @@ require_once('db.php');
//Route to the appropriate function
route();
// End of common.php
// End of common.php

View File

@ -129,7 +129,14 @@ class db extends PDO {
return self::get_instance($db);
}
function start_transaction()
{
}
function end_transaction()
{
}
}
// End of db.php

View File

@ -154,20 +154,6 @@ class Page
// --------------------------------------------------------------------------
/**
* Set an individual js file in header
* @param string $js
* @param bool $domain
* @return Page
*/
public function set_head_js($js, $domain = TRUE)
{
$this->head_js .= $this->script_tag($js, $domain);
return $this;
}
// --------------------------------------------------------------------------
/**
* Sets a minified css group
* @param string $group
@ -202,19 +188,6 @@ class Page
// --------------------------------------------------------------------------
/**
* Sets js in footer; multiple files are combined and minified.
* @param array $args
* @return Page
*/
public function set_foot_js($js, $domain)
{
$this->foot_js .= $this->script_tag($js, $domain);
return $this;
}
// --------------------------------------------------------------------------
/**
* Sets html title string
* @param string $title
@ -298,20 +271,6 @@ class Page
// --------------------------------------------------------------------------
/**
* Sets uncompressed js file in footer
* @param string $name
* @param bool $domain
* @return Page
*/
public function set_foot_js_tag($name, $domain = TRUE)
{
$this->foot_js .= $this->script_tag($name, $domain);
return $this;
}
// --------------------------------------------------------------------------
/**
* Sets a custom tag in the header
* @param string $tag
@ -490,7 +449,13 @@ class Page
}
// --------------------------------------------------------------------------
/**
* Private helper function to generate meta tags
*
* @param array $params
* @return string
*/
private function _meta($params)
{
$string = "<meta ";
@ -504,8 +469,14 @@ class Page
return $string;
}
private function _link_tag($params)
/**
* Private helper function to generate link tags
*
* @param array $params
* @return string
*/
private function _link_tag($params)
{
$string = "<link ";