Exemplo n.º 1
0
/**
 * Get request URIm compare to existing routes
 * Calls route dispatcher and binds parameter to it if it was found
 */
function handleRoute()
{
    global $routes;
    if ($_SERVER['REQUEST_METHOD'] !== 'POST' && $_SERVER['REQUEST_METHOD'] !== 'GET') {
        methodNotAllowed();
    }
    foreach ($routes as $route => $dispatcher) {
        $match = routeMatchParts($route, $_SERVER['REQUEST_URI']);
        if ($match === true) {
            callRoute($dispatcher);
            return;
        } elseif ($match !== false) {
            callRouteWithParam($dispatcher, str_replace('?' . $_SERVER['QUERY_STRING'], '', $match));
            return;
        }
    }
    renderNotFound();
}
Exemplo n.º 2
0
                $results = deleteLike($data);
                break;
            default:
                $results["meta"] = methodNotAllowed($method, $path);
        }
        break;
    case "pictures":
        switch ($method) {
            case "POST":
                $results = addPicture($data);
                break;
            case "DELETE":
                $results = deletePicture($data);
                break;
            default:
                $results["meta"] = methodNotAllowed($method, $path);
        }
        break;
    default:
        $results["meta"]["ok"] = false;
        $results["meta"]["status"] = 404;
        $results["meta"]["feedback"] = "Unrecognised URI.";
        $results["meta"]["message"] = "Not Found";
}
//send back the data provided
$results['meta']["data"] = $data;
//send back the method requested
$results['meta']["method"] = $method;
//send back the path they requested
$results['meta']["path"] = $path;
//check if requested to send json
Exemplo n.º 3
0
            case "PUT":
                $in = extractVars(INPUT_POST);
                if (isset($path[1]) && trim($path[1]) != "") {
                    $in["id"] = $path[1];
                    $results = notImplementedYet($in);
                } else {
                    $results = methodNotAllowed($in);
                }
                break;
            case "DELETE":
                $in = extractVars(INPUT_POST);
                if (isset($path[1]) && trim($path[1]) != "") {
                    $in["id"] = $path[1];
                    $results = deleteRecord($in);
                } else {
                    $results = methodNotAllowed($in);
                }
                break;
            default:
                $results["meta"]["feedback"] = "Unrecognised verb for /links GET, POST, PUT and DELETE are supported";
                $results["meta"]["status"] = 400;
                $results["meta"]["ok"] = false;
        }
        break;
    default:
        $results["meta"]["ok"] = false;
}
$results["meta"]["request"] = $in;
$results["meta"]["verb"] = $verb;
$results["meta"]["path"] = $path;
sendResults($results);