route : Add an error management in all the cases of routing. It is possible to use an external error page too.

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1827 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-09-17 12:55:53 +00:00
parent 3690760108
commit e6b0a396e4

View File

@@ -562,10 +562,7 @@ class route
}
catch (Exception $e)
{
@header ($_SERVER["SERVER_PROTOCOL"]." 500 Internal Server Error");
// TODO : Allow a specific page to be configured and displayed
echo "<H1>Internal server error</h1>";
echo $e->getMessage();
$this->error ($e);
}
exit;
}
@@ -599,42 +596,7 @@ class route
}
catch (Exception $e)
{
if ($e->getCode () === "")
$getCode = 500;
else
$getCode = $e->getCode ();
// If an error class/method is defined, use it in place of the default
// one.
// The errors must be defined in an array("class", "method");
if ($this->errors !== null)
{
if (! is_array ($this->errors))
die ("The route::\$errors is not an array\n");
if (! isset ($this->errors[0]) || ! isset ($this->errors[1]))
die ("The route::\$errors is not correct : must be the class and ".
"the method in an array\n");
$a = new $this->errors[0];
$method = $this->errors[1];
$a->$method ($getCode, $e->getMessage());
exit;
}
$http = new http ();
@header ($_SERVER["SERVER_PROTOCOL"]." $getCode ".
$http->codetext ($getCode));
// TODO : Allow a specific page to be configured and displayed
echo "<html>\n";
echo " <head>\n";
echo " <title>".$http->codetext ($getCode)."</title>\n";
echo " <meta charset='utf-8'>\n";
echo " <meta name='ROBOTS' content='NOINDEX, NOFOLLOW'>\n";
echo " </head>\n";
echo" <body>\n";
echo "<h1>".$http->codetext ($getCode)."</h1>";
echo $e->getMessage();
echo" </body>\n";
echo "</html>\n";
$this->error ($e);
}
exit;
}
@@ -642,4 +604,47 @@ class route
if ($this->debug)
echo "==> NO MATCH\n";
}
/** Print an error page. If a custom page exists, use it
@param $e Exception to print */
public function error ($e)
{
if ($e->getCode () === "")
$getCode = 500;
else
$getCode = $e->getCode ();
// If an error class/method is defined, use it in place of the default
// one.
// The errors must be defined in an array("class", "method");
if ($this->errors !== null)
{
if (! is_array ($this->errors))
die ("The route::\$errors is not an array\n");
if (! isset ($this->errors[0]) || ! isset ($this->errors[1]))
die ("The route::\$errors is not correct : must be the class and ".
"the method in an array\n");
$a = new $this->errors[0];
$method = $this->errors[1];
$a->$method ($getCode, $e->getMessage());
exit;
}
$http = new http ();
@header ($_SERVER["SERVER_PROTOCOL"]." $getCode ".
$http->codetext ($getCode));
// TODO : Allow a specific page to be configured and displayed
echo "<html>\n";
echo " <head>\n";
echo " <title>".$http->codetext ($getCode)."</title>\n";
echo " <meta charset='utf-8'>\n";
echo " <meta name='ROBOTS' content='NOINDEX, NOFOLLOW'>\n";
echo " </head>\n";
echo" <body>\n";
echo "<h1>".$http->codetext ($getCode)."</h1>";
echo $e->getMessage();
echo" </body>\n";
echo "</html>\n";
exit;
}
}