本文整理汇总了PHP中rest::reply方法的典型用法代码示例。如果您正苦于以下问题:PHP rest::reply方法的具体用法?PHP rest::reply怎么用?PHP rest::reply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest
的用法示例。
在下文中一共展示了rest::reply方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __call
public function __call($function, $args)
{
$input = Input::instance();
$request = new stdClass();
switch ($method = strtolower($input->server("REQUEST_METHOD"))) {
case "get":
$request->params = (object) $input->get();
break;
case "post":
$request->params = (object) $input->post();
if (isset($_FILES["file"])) {
$request->file = upload::save("file");
}
break;
}
$request->method = strtolower($input->server("HTTP_X_GALLERY_REQUEST_METHOD", $method));
$request->access_token = $input->server("HTTP_X_GALLERY_REQUEST_KEY");
$request->url = url::abs_current(true);
rest::set_active_user($request->access_token);
$handler_class = "{$function}_rest";
$handler_method = $request->method;
if (!method_exists($handler_class, $handler_method)) {
throw new Rest_Exception("Bad Request", 400);
}
try {
rest::reply(call_user_func(array($handler_class, $handler_method), $request));
} catch (ORM_Validation_Exception $e) {
foreach ($e->validation->errors() as $key => $value) {
$msgs[] = "{$key}: {$value}";
}
throw new Rest_Exception("Bad Request: " . join(", ", $msgs), 400);
}
}
示例2: __call
public function __call($function, $args)
{
try {
$input = Input::instance();
$request = new stdClass();
switch ($method = strtolower($input->server("REQUEST_METHOD"))) {
case "get":
$request->params = (object) $input->get();
break;
default:
$request->params = (object) $input->post();
if (isset($_FILES["file"])) {
$request->file = upload::save("file");
}
break;
}
if (isset($request->params->entity)) {
$request->params->entity = json_decode($request->params->entity);
}
if (isset($request->params->members)) {
$request->params->members = json_decode($request->params->members);
}
$request->method = strtolower($input->server("HTTP_X_GALLERY_REQUEST_METHOD", $method));
$request->access_key = $input->server("HTTP_X_GALLERY_REQUEST_KEY");
if (empty($request->access_key) && !empty($request->params->access_key)) {
$request->access_key = $request->params->access_key;
}
$request->url = url::abs_current(true);
if ($suffix = Kohana::config('core.url_suffix')) {
$request->url = substr($request->url, 0, strlen($request->url) - strlen($suffix));
}
rest::set_active_user($request->access_key);
$handler_class = "{$function}_rest";
$handler_method = $request->method;
if (!method_exists($handler_class, $handler_method)) {
throw new Rest_Exception("Bad Request", 400);
}
$response = call_user_func(array($handler_class, $handler_method), $request);
if ($handler_method == "post") {
// post methods must return a response containing a URI.
header("HTTP/1.1 201 Created");
header("Location: {$response['url']}");
}
rest::reply($response);
} catch (ORM_Validation_Exception $e) {
// Note: this is totally insufficient because it doesn't take into account localization. We
// either need to map the result values to localized strings in the application code, or every
// client needs its own l10n string set.
throw new Rest_Exception("Bad Request", 400, $e->validation->errors());
} catch (Kohana_404_Exception $e) {
throw new Rest_Exception("Not Found", 404);
}
}