2
0
mirror of https://github.com/boostorg/website.git synced 2026-01-22 05:42:52 +00:00
Files
website/common/code/bootstrap.php
Daniel James f5540f032c Fix the error_handler test cases
The problem is that when nette tester runs the tests using a CGI
executable it expects HTTP error statuses, but because it's not a real
HTTP request, SERVER_PROTOCOL isn't set. I tried to fix this before
using `http_repsonse_code` which does the right thing, but it's not
always available, so I had to revert that. So instead I've changed it so
that it assumes that it's an HTTP request unless it knows for sure that
it's a command line run.
2017-02-19 13:20:40 +00:00

59 lines
1.6 KiB
PHP

<?php
/* Bootstrap script, only for this repo.
* External code should include 'boost.php'.
*/
// Set timezone to UTC.
date_default_timezone_set('UTC');
// Die on all errors.
function error_handler($message) {
if (php_sapi_name() !== 'cli') {
$protocol = array_key_exists('SERVER_PROTOCOL', $_SERVER) ?
$_SERVER('SERVER_PROTOCOL') : 'HTTP';
@header($protocol.' 500 Internal Server Error', true, 500);
echo htmlentities($message),"\n";
}
else if (defined('STDERR')) {
fputs(STDERR, "{$message}\n");
}
else {
echo "{$message}\n";
}
exit(255);
}
set_error_handler(function($errno, $errstr, $errfile, $errline) {
if (error_reporting() & $errno) {
error_handler("{$errfile}:{$errline}: {$errstr}");
}
});
set_exception_handler(function($e) {
if ($e instanceof BoostWeb_HttpError && array_key_exists('SERVER_PROTOCOL', $_SERVER)) {
try {
BoostWeb::return_error($e);
return;
}
catch (Exception $e2) {}
}
error_handler("Uncaught exception: {$e}");
});
// Fatal errors aren't caught by the error handler, so make sure they
// return an internal server error.
register_shutdown_function(function() {
$last_error = error_get_last();
if ($last_error && $last_error['type'] & (E_ERROR|E_PARSE|E_CORE_ERROR|E_COMPILE_ERROR)) {
if (array_key_exists('SERVER_PROTOCOL', $_SERVER)) {
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
}
}
});
// General setup.
require_once(__DIR__.'/boost.php');