From 3cd475a0d9b77ca52f697b90f3480732739a9cd9 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Tue, 16 Sep 2014 11:34:37 +0000 Subject: [PATCH] route : Add support to errors from the application git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1820 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- route.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/route.php b/route.php index 0e39720..2b35f6d 100644 --- a/route.php +++ b/route.php @@ -21,6 +21,10 @@ class route public $debug=0; //public $defaultOutput = "html"; // Default renderer : html + // Provide the static class::method to errors in routing. + // Must be provided in an array(class,method); + public $errors = null; + /** Return the baseURL of the site Always finish with a slash @param string|null $module The module name (if thereis one) */ @@ -600,8 +604,19 @@ class route else $getCode = $e->getCode (); + // If an error class/method is defined, use it in place of the default + // one. + // The error method must be a "static public function" + // The errors must be defined in an array ("class", "method"); + if ($this->errors !== null) + { + forward_static_call($this->errors, $getCode, $e->getMessage()); + exit; + } + $http = new http (); - @header ($_SERVER["SERVER_PROTOCOL"]." $getCode ".$http->codetext ($getCode)); + @header ($_SERVER["SERVER_PROTOCOL"]." $getCode ". + $http->codetext ($getCode)); // TODO : Allow a specific page to be configured and displayed echo "\n"; echo " \n";