This repository has been archived by the owner on May 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbootstrap.php
160 lines (140 loc) · 3.98 KB
/
bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
namespace rpf;
use rpf\system\module\exception;
use rpf\system\module\log;
/**
* Report all errors
*/
error_reporting(E_ALL);
/**
* Location to store the bbRpc-Cookie
*/
define('BBRPC_COOKIE', '/tmp/RPF_bbRpc_cookie.txt');
/**
* Debug-Mode?
*/
define('RPF_DEBUG', true);
/**
* Let us use a autoloader for our classes.
* (cause nobody likes require_once)
*
* @param $class
* @return bool
* @throws \Exception
*/
function classLoader ($class)
{
$path = explode('\\', $class);
unset($path[0]); //Namespace 'rpf'
$file = __DIR__ . '/class';
foreach ($path as $name) {
$file .= "/$name";
}
$file .= '.php';
if (file_exists($file)) {
require_once $file;
$logFileName = str_replace(__DIR__, '', $file);
log::debug("Include $logFileName", __FUNCTION__ . "('$class')");
return true;
} else {
log::error("Couldn't load class from '$file'", __FUNCTION__."($class)");
echo "<pre>";
throw new \Exception("File $file not found");
return false;
}
}
spl_autoload_register('\rpf\classLoader');
/**
* @param $title
* @param $text
* @param string $code
* @todo move to extension/error
*/
function showError($title, $text, $code = '')
{
?>
<head>
<style>
body
{
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#errorLayer
{
background: white url("/extension/static/sadMumby.jpg")no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
z-index: 20;
height: 100%;
width: 100%;
background-repeat:no-repeat;
background-position:center;
position:absolute;
top: 0px;
left: 0px;
}
#error
{
position: absolute;
top: 0px;
left: 0px;
margin: 30px;
padding: 30px;
width: 350px;
word-wrap:break-word;
color: white;
background: black;
opacity: 0.5;
}
#error h1
{
font-size: 1.5em;
margin-top:0;
}
#error pre
{
height: 300px;
overflow: auto;
}
</style>
</head>
<body>
<div id="errorLayer">
<div id="error">
<h1><?=$title?></h1>
<?=$text?>
</div>
</div>
</body>
<?php
}
/**
* @param \Exception $exception
* @return bool
*/
function exceptionHandler(\Exception $e)
{
showError('Sorry, the script died with a exception', $e->getMessage(), $e->getCode());
log::error($e->getMessage().' in '.$e->getFile().':'.$e->getLine(), __FUNCTION__,$e->getTrace());
die('-die-');
}
set_exception_handler('rpf\exceptionHandler');
//throw new exception('yow!', 200);
/**
* Lets pass all php-errors to our syslog
*
* @param $errorNumber
* @param $errorString
* @param $errorFile
* @param $errorLine
* @return bool
*/
function errorHandler($errorNumber, $errorString, $errorFile, $errorLine)
{
showError("Sorry, the script died with a PHP-Error", $errorString.' in '.$errorFile.':'.$errorLine);
log::error("PHP-ERROR\n\n!!!!! $errorString\n!!!!! $errorFile:$errorLine\n", __METHOD__, debug_backtrace());
die();
}
set_error_handler('rpf\errorHandler');