if ($config->get('config_error_display')) {
        echo '<b>' . $error . '</b>: ' . $message . ' in <b>' . $file . '</b> on line <b>' . $line . '</b>';
    }
    if ($config->get('config_error_log')) {
        $log->write('PHP ' . $error . ':  ' . $message . ' in ' . $file . ' on line ' . $line);
    }
    return true;
}
// Error Handler
set_error_handler('error_handler');
// Request
$request = new ApiRequest($registry);
$registry->set('request', $request);
// Response
$response = new ApiResponse($registry);
$response->addHeader('Content-Type: application/json');
$response->setCompression($config->get('config_compression'));
$registry->set('response', $response);
// Auth
$registry->set('oauth', new Authentication($registry));
// Cache
$cache = new Cache('file');
$registry->set('cache', $cache);
// Session
if (isset($request->get['token']) && isset($request->get['route']) && substr($request->get['route'], 0, 4) == 'api/') {
    $db->query("DELETE FROM `" . DB_PREFIX . "restapi_session` WHERE TIMESTAMPADD(HOUR, 1, date_modified) < NOW()");
    $query = $db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "api` `a` LEFT JOIN `" . DB_PREFIX . "restapi_session` `as` ON (a.api_id = as.api_id) LEFT JOIN " . DB_PREFIX . "api_ip `ai` ON (as.api_id = ai.api_id) WHERE a.status = '1' AND as.token = '" . $db->escape($request->get['token']) . "' AND ai.ip = '" . $db->escape($request->server['REMOTE_ADDR']) . "'");
    if ($query->num_rows) {
        // Does not seem PHP is able to handle sessions as objects properly so so wrote my own class
        $session = new Session($query->row['session_id'], $query->row['session_name']);
        $registry->set('session', $session);