function ajaxShutdown() { $isError = false; if ($error = error_get_last()) { switch ($error['type']) { case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: case E_PARSE: $log_file = ini_get("error_log"); if (file_exists($log_file)) { $number_of_characters_to_get = 5000; $bf = new BigFile($log_file); $text = $bf->getFromEnd($number_of_characters_to_get); $lines = array_reverse(explode("\n", $text)); $backtrace = ""; foreach ($lines as $i => $line) { if (strstr($line, "Fatal")) { for ($j = $i; $j > 0; $j--) { $backtrace .= $lines[$j] . "\n"; } break; } } if ($backtrace == "") { $backtrace = "No Fatal error found in the last {$number_of_characters_to_get} lines of {$log_file}"; } } else { $backtrace = "No error log found at " . $log_file; } $isError = true; break; } } if ($isError) { send_http_error(new Exception("E_ERROR " . $error['message'] . "\n file: " . $error['file'] . " (" . $error['line'] . ")", E_FATAL_ERROR), "FATAL ERROR. shutdown function tried to restore backtrace from php error log ({$log_file}):\n" . $backtrace, true); $response = new HttpResponse(); $response->setStatus("400 Bad Request"); $response->write("E_ERROR " . $error['message'] . "\n file: " . $error['file'] . " (" . $error['line'] . ")"); $response->flush(); } }
public function handleRequest(AjaxRequestObject $ajaxRequestObject, AjaxResponseObject $ajaxResponseObject) { $response = new HttpResponse(); $extension = ExtensionMaster::getInstance()->getExtensionForNamespace($ajaxRequestObject->getNamespace()); if (isset($extension)) { if ($extension instanceof ICommandAdapter) { if ($ajaxRequestObject->getCommand() != "") { if ($ajaxRequestObject->getCommand() == "databinding") { $command = new Databinding(); } else { if ($extension->isValidCommand($ajaxRequestObject->getCommand())) { $command = $extension->getCommand($ajaxRequestObject->getCommand()); } } if ($command instanceof IAjaxCommand && $command->validateData($ajaxRequestObject)) { try { $command->processData($ajaxRequestObject); $ajaxResponseObject = $command->ajaxResponse($ajaxResponseObject); } catch (Exception $e) { $response->setStatus("400 Bad Request"); $response->write("Command processing error: \"{$e->getMessage()}\""); $response->flush(); if (DEVELOPMENT_MODE) { throw $e; } exit; } if ($ajaxResponseObject instanceof AjaxResponseObject) { $data = \Widgets\Widget::getData($ajaxResponseObject->getWidgets()); $stat = ""; if ($_SESSION["STATISTICS_LEVEL"] > 0) { $stat = "console.log('Serveranfragen: " . $GLOBALS["STEAM"]->get_request_count() . " / " . $GLOBALS["STEAM"]->get_globalrequest_count() . "');"; } if ($_SESSION["STATISTICS_LEVEL"] > 1 && isset($GLOBALS["page_time_start"])) { $requestMap = $GLOBALS["STEAM"]->get_globalrequest_map(); $requestTime = $GLOBALS["STEAM"]->get_globalrequest_time(); $requestString = ""; foreach ($requestMap as $method => $count) { $requestString .= "console.log('Methode {$method} -> {$count} mal in " . round($requestTime[$method] * 1000) . " ms');"; } $stat .= "console.log('Zeit: " . round((microtime(TRUE) - $GLOBALS["page_time_start"]) * 1000) . " ms');" . $requestString; } header("Content-type: text/plain"); $response->write(json_encode(array("status" => $ajaxResponseObject->getStatus(), "html" => $data["html"], "data" => $ajaxResponseObject->getData(), "css" => $data["css"], "js" => $data["js"] . $stat, "postjs" => $data["postjs"]))); $response->flush(); exit; } else { $response->setStatus("400 Bad Request"); $response->write("Wrong response type for \"{$ajaxRequestObject->getCommand()}\""); $response->flush(); exit; } } else { $response->setStatus("400 Bad Request"); $response->write("Command \"{$ajaxRequestObject->getCommand()}\" not valid."); $response->flush(); exit; } } else { $response->setStatus("400 Bad Request"); $response->write("Command parameter missing."); $response->flush(); exit; } } else { $response->setStatus("400 Bad Request"); $response->write("Extension doesn't support commands."); $response->flush(); exit; } } else { $response->setStatus("400 Bad Request"); $response->write("Not extension found for url"); $response->flush(); exit; } }
<?php require_once "errors.php"; require_once "Exceptions.php"; require_once "db.php"; require_once 'HttpRequest.php'; require_once 'HttpResponse.php'; require_once 'Authenticator.php'; require_once 'Router.php'; require_once 'Trips.php'; $resp = new HttpResponse(); try { $db = new mysqli($dbhost, $dbuser, $dbpw, $dbdb); $req = new HttpRequest(); $auth = new Authenticator($db, $req); //the router handles all of the other stuff (loading controller etc.) $router = new Router($req, $resp, $db, $auth); $content = $router->executeRoute(); $resp->write($content); $resp->flush(); } catch (Exception $e) { $resp->setStatus(400); $resp->addHeader('error', $e->getMessage()); $resp->write('{"exception" : "' . $e->getMessage() . ' [' . $e->getFile() . '#' . $e->getLine() . ']"}'); $resp->flush(); }