Example #1
0
function route()
{
    $method = $_SERVER['REQUEST_METHOD'];
    $request = explode("/", substr(@$_SERVER['PATH_INFO'], 1));
    $pathParameters = array();
    $pathName = array_shift($request);
    for ($x = 0; $x < count($request); $x += 2) {
        $v = isset($request[$x + 1]) ? $request[$x + 1] : NULL;
        $pathParameters[$request[$x]] = $v;
    }
    $params = array_merge($_GET, $_POST, $pathParameters);
    $actionName = ucfirst($pathName);
    $action = 'Action' . $actionName;
    try {
        $exists = class_exists($action);
    } catch (ClassNotFoundException $e) {
        error_not_found($actionName);
    }
    if ($exists && in_array('Rest', class_implements($action))) {
        $a = new $action();
        $m = 'do' . $method;
        if (method_exists($a, $m)) {
            $a->parameters = $params;
            $a->headers = getallheaders();
            try {
                $a->{$m}();
            } catch (Exception $e) {
                error_internal_server_error($e->getMessage());
                throw $e;
            }
            // after executed, we must be sure nothing else happen.
            exit;
        } else {
            error_method_not_allowed($method);
        }
    } else {
        error_not_found("Not found: " . $request[0]);
    }
}
 function doDELETE()
 {
     $this->allowFromKey();
     $graph = $this->assertNotEmpty('graph');
     _debug('DELETE graph ' . $graph);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, 'http://localhost:4444/catalogue/data?graph=' . urlencode($graph));
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
     #curl_setopt($ch, CURLOPT_DELETE, 1);
     $server_output = curl_exec($ch);
     $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     curl_close($ch);
     #error_log("Executed Catalogue::DELETE . Response: " . $http_code, 0);
     if (strpos($http_code, '2') === 0) {
         // OK
         header("HTTP/1.1 " . $http_code, true, $http_code);
         exit(0);
         // Die happy
     } else {
         // Any other is a failure
         error_internal_server_error("Response was: " . $server_output);
     }
 }