summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDracony <draconyster@gmail.com>2013-01-16 11:35:15 +0200
committerDracony <draconyster@gmail.com>2013-01-16 11:35:15 +0200
commit7fb4281b83a1b34576481a9ad94405b98fabbed0 (patch)
tree16a275d12bc66d2a87862fb31b79faa6e0dbbd0f
parentfa32e343b46545fa2d26688d4282af179960c10a (diff)
downloadPHPixie-7fb4281b83a1b34576481a9ad94405b98fabbed0.zip
PHPixie-7fb4281b83a1b34576481a9ad94405b98fabbed0.tar.gz
PHPixie-7fb4281b83a1b34576481a9ad94405b98fabbed0.tar.bz2
Custom error handling support
-rw-r--r--system/classes/controller.php2
-rw-r--r--system/classes/debug.php20
-rw-r--r--system/classes/error.php100
-rw-r--r--system/classes/request.php4
-rw-r--r--system/classes/route.php6
5 files changed, 14 insertions, 118 deletions
diff --git a/system/classes/controller.php b/system/classes/controller.php
index 664710f..a1aff33 100644
--- a/system/classes/controller.php
+++ b/system/classes/controller.php
@@ -72,7 +72,7 @@ class Controller {
public function run($action) {
$action = 'action_'.$action;
if (!method_exists($this, $action))
- throw new Exception("Method {$action} doesn't exist in ".get_class($this));
+ throw new Exception("Method {$action} doesn't exist in ".get_class($this),404);
$this->execute=true;
$this->before();
if($this->execute)
diff --git a/system/classes/debug.php b/system/classes/debug.php
index d066e26..4947054 100644
--- a/system/classes/debug.php
+++ b/system/classes/debug.php
@@ -7,13 +7,6 @@
class Debug {
/**
- * Caught exception
- * @var Exception
- * @access public
- */
- public $exception;
-
- /**
* An array of logged items
* @var array
* @access public
@@ -27,10 +20,10 @@ class Debug {
* @return void
* @access public
*/
- public function render() {
+ public function render_error($exception) {
ob_end_clean();
$view = View::get('debug');
- $view->exception = $this->exception;
+ $view->exception = $exception;
$view->log = Debug::$logged;
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
header("Status: 404 Not Found");
@@ -38,7 +31,9 @@ class Debug {
}
/**
- * Catches errors and exceptions and processes them
+ * Catches errors and exceptions and sends them
+ * to the configured handler if one is present,
+ * otherwise render_error() will be called.
*
* @param Exception $exception Caught exception
* @return void
@@ -48,9 +43,8 @@ class Debug {
public static function onError($exception) {
set_exception_handler(array('Debug', 'internalException'));
set_error_handler ( array('Debug', 'internalError'), E_ALL);
- $error = new Debug();
- $error->exception = $exception;
- $error->render();
+ $handler = Config::get('core.error_handler', 'Debug::render_error');
+ call_user_func($handler,$exception);
}
/**
diff --git a/system/classes/error.php b/system/classes/error.php
deleted file mode 100644
index 24a8d14..0000000
--- a/system/classes/error.php
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-
-/**
- * Short description for class.
- * @package Core
- */
-class Error {
-
- /**
- * Description for public
- * @var unknown
- * @access public
- */
- public $exception;
-
- /**
- * Short description for function
- *
- * @return void
- * @access public
- */
- public function render() {
- ob_end_clean();
- $view = View::get('error');
- $view->exception = $this->exception;
- echo $view->render();
- }
-
- /**
- * Short description for function
- *
- * @param unknown $exception Parameter description (if any) ...
- * @return void
- * @access public
- * @static
- */
- public static function onError($exception) {
- set_exception_handler(array('Error', 'internalException'));
- set_error_handler ( array('Error', 'internalError'), E_ALL);
- $error = new Error();
- $error->exception = $exception;
- $error->render();
- }
-
- /**
- * Short description for function
- *
- * @param unknown $errno Parameter description (if any) ...
- * @param unknown $errstr Parameter description (if any) ...
- * @param unknown $errfile Parameter description (if any) ...
- * @param unknown $errline Parameter description (if any) ...
- * @return void
- * @access public
- * @throws ErrorException Exception description (if any) ...
- * @static
- */
- public static function errorHandler($errno, $errstr, $errfile, $errline) {
- throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
- }
-
- /**
- * Short description for function
- *
- * @param mixed $exception Parameter description (if any) ...
- * @return void
- * @access public
- * @static
- */
- public static function internalException($exception) {
- echo $exception->getMessage().' in '.$exception->getFile().' on line '.$exception->getLine();
- }
-
- /**
- * Short description for function
- *
- * @param unknown $errno Parameter description (if any) ...
- * @param string $errstr Parameter description (if any) ...
- * @param string $errfile Parameter description (if any) ...
- * @param string $errline Parameter description (if any) ...
- * @return void
- * @access public
- * @static
- */
- public static function internalError($errno, $errstr, $errfile, $errline) {
- echo $errstr.' in '.$errfile.' on line '.$errline;
- }
-
- /**
- * Short description for function
- *
- * @return void
- * @access public
- * @static
- */
- public static function init(){
- set_exception_handler(array('Error', 'onError'));
- set_error_handler ( array('Error', 'errorHandler'), E_ALL);
- }
-
-} \ No newline at end of file
diff --git a/system/classes/request.php b/system/classes/request.php
index 167bbab..dfe68f0 100644
--- a/system/classes/request.php
+++ b/system/classes/request.php
@@ -86,7 +86,9 @@ class Request {
* @access public
*/
public function execute() {
- $controller=$this->param('controller').'_Controller';
+ $controller = $this->param('controller').'_Controller';
+ if (!class_exists($controller))
+ throw new Exception("Class {$controller} doesn't exist",404);
$controller = new $controller;
$controller->request = $this;
$controller->run($this->param('action'));
diff --git a/system/classes/route.php b/system/classes/route.php
index e885456..3eadb1f 100644
--- a/system/classes/route.php
+++ b/system/classes/route.php
@@ -109,15 +109,15 @@ class Route {
}
}
if($matched==false)
- throw new Exception('No route matched your request');
+ throw new Exception('No route matched your request',404);
$rule=Route::$rules[$matched];
$params=array_merge($rule['defaults'],$data);
if(!isset($params['controller']))
- throw new Exception("Route {$matched} matched, but no controller was defined for this route");
+ throw new Exception("Route {$matched} matched, but no controller was defined for this route",404);
if(!isset($params['action']))
- throw new Exception("Route {$matched} matched with controller {$params['controller']}, but no action was defined for this route");
+ throw new Exception("Route {$matched} matched with controller {$params['controller']}, but no action was defined for this route",404);
$route=Route::get($matched);
$route->params=$params;