Project

General

Profile

1
<?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
		public function __toString() {
25
			$file = str_replace(dirname(dirname(__FILE__)), '', $this->getFile());
26
			$out  = '<div style="color: #ff0000; text-align: center;"><br />';
27
			$out .= '<br /><br /><h1>Illegale file access</h1>';
28
			$out .= '<h2>'.$file.'</h2></div>';
29
			return $out;
30
		}
31
	} // end of class
32

    
33
/**
34
 *
35
 * @param Exception $e
36
 */
37
	function globalExceptionHandler($e) {
38
		// hide server internals from filename where the exception was thrown
39
		$file = str_replace(dirname(dirname(__FILE__)), '', $e->getFile());
40
		// select some exceptions for special handling
41
		if ($e instanceof IllegalFileException) {
42
			$sResponse  = $_SERVER['SERVER_PROTOCOL'].' 403 Forbidden';
43
			header($sResponse);
44
			echo $e;
45
		}elseif($e instanceof RuntimeException) {
46
			$out  ='There was a serious runtime error:'."\n";
47
			$out .= $e->getMessage()."\n";
48
			$out .= 'in line ('.$e->getLine().') of ('.$file.')'."\n";
49
			echo $out;
50
		}else {
51
		// default exception handling
52
			$out  = 'There was an unknown exception:'."\n";
53
			$out .= $e->getMessage()."\n";
54
			$out .= 'in line ('.$e->getLine().') of ('.$file.')'."\n";
55
			echo $out;
56
		}
57
	}
58
/**
59
 * now activate the new defined handler
60
 */
61
	set_exception_handler('globalExceptionHandler');
(19-19/22)