示例#1
0
$uri = $rest->getPath();
$verb = $rest->getMethod();
header('Access-Control-Allow-Headers:Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, X-Auth-Token');
//header('Access-Control-Allow-Methods:'.$verb);
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Origin:*');
header('Access-Control-Max-Age:86400');
// Adjust per your expectations from the software you're using
$regex = preg_match('/\\/(.*)\\/accounts\\/(.*)\\/(.*)\\/(.*)/', $uri) ? '/\\/(.*)\\/accounts\\/(.*)\\/(.*)\\/(.*)/' : '/\\/(.*)\\/accounts\\/(.*)\\/(.*)/';
$handler->regex = $regex;
preg_match($regex, $uri, $matches);
$version = $matches[1];
$account_id = $matches[2];
$method = $matches[3];
$id = $matches[4];
$data = $rest->getData();
$handler->json_error();
//$method = 'provision';
if (isset($id)) {
    switch ($method) {
        case 'provision':
            $response = $handler->{$verb}($uri, json_encode($data));
            if ($response && $verb == 'GET') {
                $response = json_decode($response);
            }
            break;
        case 'provision_template':
            $response = $handler->{$verb}($uri, json_encode($data));
            if ($response && $verb == 'GET') {
                $response = json_decode($response);
            }
示例#2
0
 /**
  * @return mixed|string data of request body
  */
 public function getRequestBody()
 {
     $restServer = new RestServer('debug');
     $restServer->format = 'json';
     return $restServer->getData();
 }