/** * Initialise the database from the config settings. */ public static function init() { if (self::$connected) { return; } self::$connection = mysqli_connect(Config::getDatabaseHost(), Config::getDatabaseUser(), Config::getDatabasePassword(), Config::getDatabaseName()); if (mysqli_connect_errno() != 0) { throw new DatabaseException(mysqli_error(self::$connection)); } self::$connected = true; }
require_once 'Routes.php'; // Setup response formats $formats = []; $formats["json"] = new response\JsonResponseFormat(false); $formats["json/pretty"] = new response\JsonResponseFormat(true); $formats["xml"] = new response\XMLResponseFormat(); // Get response response if provided $responseFormat = DEFAULT_FORMAT; if (array_key_exists(Headers::RESPONSE_FORMAT, $_SERVER)) { $responseFormat = $_SERVER[Headers::RESPONSE_FORMAT]; } error_reporting(DEBUG ? E_ALL : 0); require_once 'core/Utils.php'; require_once 'Routes.php'; // Setup config core\Config::loadConfig(); database\Database::init(); // Request from the same server don't have a HTTP_ORIGIN if (!array_key_exists('HTTP_ORIGIN', $_SERVER)) { $_SERVER['HTTP_ORIGIN'] = $_SERVER['SERVER_NAME']; } // Get response response if provided $responseFormat = DEFAULT_FORMAT; if (array_key_exists(Headers::RESPONSE_FORMAT, $_SERVER)) { $responseFormat = $_SERVER[Headers::RESPONSE_FORMAT]; } $code = HTTP::INTERNAL_ERROR; $payload = []; // get the requested endpoint $request = strtolower($_REQUEST['request']); // Sanitize the request