/** * Handle Error * Handles all errors and exceptions * * @param string $error_type Type of error * @param string $error_string Actual error string * @param string $error_file File error happened in * @param string $error_line Line error happened on * @return bool True on pass */ public function handle_error($error_type = "", $error_string = "", $error_file = "", $error_line = "") { $error_group = 'log'; // changeing log type to chrome php $type = ''; if (is_int($error_type)) { switch ($error_type) { case E_ERROR: // 1 // $error_group = 'error'; $type = 'E_ERROR'; break; case E_WARNING: // 2 // $error_group = 'warn'; $type = 'E_WARNING'; break; case E_PARSE: // 4 // $type = 'E_PARSE'; break; case E_NOTICE: // 8 // $type = 'E_NOTICE'; break; case E_CORE_ERROR: // 16 // $error_group = 'error'; $type = 'E_CORE_ERROR'; break; case E_CORE_WARNING: // 32 // $error_group = 'warn'; $type = 'E_CORE_WARNING'; break; case E_CORE_ERROR: // 64 // $error_group = 'error'; $type = 'E_COMPILE_ERROR'; break; case E_CORE_WARNING: // 128 // $error_group = 'warn'; $type = 'E_COMPILE_WARNING'; break; case E_USER_ERROR: // 256 // $error_group = 'error'; $type = 'E_USER_ERROR'; break; case E_USER_WARNING: // 512 // $error_group = 'warn'; $type = 'E_USER_WARNING'; break; case E_USER_NOTICE: // 1024 // $type = 'E_USER_NOTICE'; break; case E_STRICT: // 2048 // $type = 'E_STRICT'; break; case E_RECOVERABLE_ERROR: // 4096 // $error_group = 'error'; $type = 'E_RECOVERABLE_ERROR'; break; case E_DEPRECATED: // 8192 // $type = 'E_DEPRECATED'; break; case E_USER_DEPRECATED: // 16384 // $type = 'E_USER_DEPRECATED'; break; } } $error['error'] = $type; $error['type'] = $error_type; $error['file'] = $error_file; $error['line'] = $error_line; $error['string'] = $error_string; $error['group'] = $error_group; // log error self::log_error($error); // log error to chromephp self::chrome_php($error, false); // display error on screen self::display_error($error); if (class_exists("RarsAPI")) { RarsAPI::response(null, null, 500); } else { return true; } }
$path_parts = explode("/", $_GET["path"]); $filename = ""; $classname = ""; $found = false; $c = 0; foreach ($path_parts as $pp) { $c++; $filename .= "/" . preg_replace("/[^a-z0-9_-]/", '', strtolower($pp)); $classname .= ucfirst(preg_replace("/[^a-z0-9_]/", '', strtolower($pp))); if (is_file(RARS_BASE_PATH . "api{$filename}.php")) { $found = true; break; } } if (!$found) { RarsAPI::response(null, null, $code = 404); } // grab any data or id's data if ($method == "delete" || $method == "get") { $data = count($path_parts) == $c + 1 ? RarsAPI::clean_data($path_parts[$c]) : (count($path_parts) == $c + 2 ? RarsAPI::clean_data($path_parts[$c + 1]) : null); } else { $data = RarsAPI::clean_data(!empty($_POST) ? $_POST : json_decode(file_get_contents('php://input'))); } // load resource or throw error include RARS_BASE_PATH . "api{$filename}.php"; $resource = new $classname(); if (!method_exists($resource, $method)) { RarsAPI::response(null, null, $code = 405); } $response = $resource->{$method}($data); /* EOF */