2 /*------------------------------------------------------------
3 * CarbonPHP framework (C) Tom Bell
4 * http://tombell.org.uk
5 *------------------------------------------------------------*/
7 if (!defined('CARBON_PATH'))
9 exit('Direct script access is not allowed.');
12 class Carbon_Exception
14 protected $exc_levels = array(
16 E_WARNING
=> 'Warning',
17 E_PARSE
=> 'Parsing error',
19 E_CORE_ERROR
=> 'Core error',
20 E_CORE_WARNING
=> 'Core warning',
21 E_COMPILE_ERROR
=> 'Compile error',
22 E_COMPILE_WARNING
=> 'Compile warning',
23 E_USER_ERROR
=> 'User error',
24 E_USER_WARNING
=> 'User warning',
25 E_USER_NOTICE
=> 'User notice',
26 E_STRICT
=> 'Runtime notice'
29 protected $exc_action;
30 protected $exc_severity;
31 protected $exc_message;
32 protected $exc_ob_level;
34 public function __construct()
36 $this->exc_ob_level
= ob_get_level();
39 public function log_exception($severity, $message, $file_path, $line_number)
41 $severity = (!isset($this->exc_levels
[$severity])) ?
$severity : $this->exc_levels
[$severity];
42 log_message('error', 'Exception.php - Severity: ' . $severity. ' -> ' . $message . ' ' . $file_path . ' ' . $line_number, true);
45 public function display_not_found($page = '')
47 $page_heading = '404: Page Not Found';
48 $page_message = 'The page you have requested could not be found.';
49 log_message('error', 'Exception.php - 404 page not found: ' . $page);
50 echo $this->display_error($page_heading, $page_message, 'error_404');
54 public function display_error($heading, $message, $template = 'error')
56 $message = '<p>' . implode('</p><p>' , (!is_array($message)) ?
array($message) : $message) . '</p>';
58 if (ob_get_level() > $this->exc_ob_level +
1)
64 include(APP_PATH
. 'errors/' . $template . FILE_EXT
);
65 $buffer = ob_get_contents();
71 public function display_php_error($severity, $message, $file_path, $line_number)
73 $severity = (!isset($this->exc_levels
[$severity])) ?
$severity : $this->exc_levels
[$severity];
74 $file_path = str_replace('\\', '/', $file_path);
76 if (!strpos($file_path, '/'))
78 $x = explode('/', $file_path);
79 $file_path = $x[count($x) - 2] . '/' . end($x);
82 if (ob_get_level() > $this->exc_ob_level +
1)
89 include(APP_PATH
. 'errors/error_php' . FILE_EXT
);
91 $buffer = ob_get_contents();