1 |
1488
|
DarkViper
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @category WebsiteBaker
|
4 |
|
|
* @package WebsiteBaker_core
|
5 |
|
|
* @author Werner v.d.Decken
|
6 |
|
|
* @copyright WebsiteBaker.org e.V.
|
7 |
|
|
* @link http://websitebaker2.org
|
8 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
9 |
|
|
* @version $Id: class.order.php 1487 2011-08-10 13:20:15Z DarkViper $
|
10 |
|
|
* @filesource $HeadURL: http://svn.websitebaker2.org/branches/2.8.x/wb/framework/class.order.php $
|
11 |
|
|
*
|
12 |
|
|
* Global exception-handler
|
13 |
|
|
* This module will activate a global exception handler to catch all thrown exceptions
|
14 |
|
|
*
|
15 |
|
|
*/
|
16 |
|
|
/**
|
17 |
|
|
* define several default exceptions directly to prevent from extra loading requests
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
/**
|
21 |
|
|
* define Exception to show error after accessing a forbidden file
|
22 |
|
|
*/
|
23 |
|
|
class IllegalFileException extends LogicException {
|
24 |
|
|
|
25 |
|
|
public function __toString() {
|
26 |
|
|
$file = str_replace(dirname(dirname(__FILE__)), '', $e->getFile());
|
27 |
|
|
$out = '<div style="color: #ff0000; text-align: center;"><br /><br /><br /><h1>Illegale file access</h1>';
|
28 |
|
|
$out .= '<h2>'.$file.'</h2></div>';
|
29 |
|
|
return $out;
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
} // end of class
|
33 |
|
|
|
34 |
|
|
/**
|
35 |
|
|
*
|
36 |
|
|
* @param Exception $e
|
37 |
|
|
*/
|
38 |
|
|
function globalExceptionHandler($e) {
|
39 |
|
|
// hide server internals from filename where the exception was thrown
|
40 |
|
|
$file = str_replace(dirname(dirname(__FILE__)), '', $e->getFile());
|
41 |
|
|
// select some exceptions for special handling
|
42 |
|
|
if ($e instanceof IllegalFileException) {
|
43 |
|
|
$sResponse = $_SERVER['SERVER_PROTOCOL'].' 403 Forbidden';
|
44 |
|
|
header($sResponse);
|
45 |
|
|
echo $e;
|
46 |
|
|
}else {
|
47 |
|
|
// default exception handling
|
48 |
|
|
$out = 'There was an unknown exception:'."\n";
|
49 |
|
|
$out .= $e->getMessage()."\n";
|
50 |
|
|
$out .= 'in line ('.$e->getLine().') of ('.$file.')'."\n";
|
51 |
|
|
echo $out;
|
52 |
|
|
}
|
53 |
|
|
}
|
54 |
|
|
/**
|
55 |
|
|
* now activate the new defined handler
|
56 |
|
|
*/
|
57 |
|
|
set_exception_handler('globalExceptionHandler');
|