Newer
Older
Jaime Perez Crespo
committed
// initialize the autoloader
require_once(dirname(dirname(__FILE__)).'/lib/_autoload.php');
Jaime Perez Crespo
committed
// enable assertion handler for all pages
SimpleSAML_Error_Assertion::installHandler();
Jaime Perez Crespo
committed
// show error page on unhandled exceptions
function SimpleSAML_exception_handler($exception)
Jaime Perez Crespo
committed
{
SimpleSAML\Module::callHooks('exception_handler', $exception);
Jaime Perez Crespo
committed
if ($exception instanceof SimpleSAML_Error_Error) {
$exception->show();
} elseif ($exception instanceof Exception) {
Jaime Perez Crespo
committed
$e = new SimpleSAML_Error_Error('UNHANDLEDEXCEPTION', $exception);
$e->show();
} else {
if (class_exists('Error') && $exception instanceof Error) {
$code = $exception->getCode();
$errno = ($code > 0) ? $code : E_ERROR;
$errstr = $exception->getMessage();
$errfile = $exception->getFile();
$errline = $exception->getLine();
SimpleSAML_error_handler($errno, $errstr, $errfile, $errline);
}
Jaime Perez Crespo
committed
}
Jaime Perez Crespo
committed
set_exception_handler('SimpleSAML_exception_handler');
Jaime Perez Crespo
committed
// log full backtrace on errors and warnings
function SimpleSAML_error_handler($errno, $errstr, $errfile = null, $errline = 0, $errcontext = null)
{
if (!class_exists('SimpleSAML\Logger')) {
Jaime Perez Crespo
committed
/* We are probably logging a deprecation-warning during parsing. Unfortunately, the autoloader is disabled at
* this point, so we should stop here.
*
* See PHP bug: https://bugs.php.net/bug.php?id=47987
*/
return false;
}
if (SimpleSAML\Logger::isErrorMasked($errno)) {
Jaime Perez Crespo
committed
// masked error
return false;
}
Jaime Perez Crespo
committed
static $limit = 5;
$limit -= 1;
if ($limit < 0) {
// we have reached the limit in the number of backtraces we will log
return false;
}
Jaime Perez Crespo
committed
// show an error with a full backtrace
$e = new SimpleSAML_Error_Exception('Error '.$errno.' - '.$errstr);
$e->logError();
Jaime Perez Crespo
committed
// resume normal error processing
return false;
Jaime Perez Crespo
committed
set_error_handler('SimpleSAML_error_handler');
try {
SimpleSAML_Configuration::getInstance();
} catch (Exception $e) {
Jaime Perez Crespo
committed
throw new \SimpleSAML\Error\CriticalConfigurationError(
Jaime Pérez
committed
$e->getMessage()
Jaime Perez Crespo
committed
);
}
Jaime Perez Crespo
committed
// set the timezone
SimpleSAML\Utils\Time::initTimezone();