本文整理汇总了PHP中MainController::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP MainController::getResponse方法的具体用法?PHP MainController::getResponse怎么用?PHP MainController::getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MainController
的用法示例。
在下文中一共展示了MainController::getResponse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: explode
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: accept, authorization, content-type");
header("Access-Control-Allow-Methods: PUT, DELETE, POST, GET, OPTIONS");
// Store request method
$method = $_SERVER['REQUEST_METHOD'];
// Store path
if (array_key_exists("PATH_INFO", $_SERVER)) {
$path = explode('/', $_SERVER['PATH_INFO']);
$path = trimPath($path, 1);
} else {
$path = array();
}
// Store payload - JSON that is sent with the request
$payload = file_get_contents('php://input');
if ($payload) {
$body = json_decode($payload, true);
} else {
$body = array();
}
// If there are no errors in the JSON, instantiate MainController
if (json_last_error() == JSON_ERROR_NONE) {
$req = new MainController($path, $method, $body);
$response = $req->getResponse();
} else {
$response = new ErrorResponse(new InvalidJSONError($payload));
}
// Set content type and response code for the result
header($response->getContentType());
http_response_code($response->getResponseCode());
// Print the JSON result of request
echo $response->getBody();