本文整理汇总了PHP中Illuminate\Http\Response::setStatusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setStatusCode方法的具体用法?PHP Response::setStatusCode怎么用?PHP Response::setStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Response
的用法示例。
在下文中一共展示了Response::setStatusCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
public function handle($request, Closure $next)
{
$response = new Response();
if (Auth::check() === false) {
$request->request->set('roleId', $this->retrieveRoleIdByName('Customer'));
return $next($request);
}
$user = Auth::user();
if ($user === null) {
$response->header(Constants::RESPONSE_HEADER, "Failed to retrieve authenticated user.");
$response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
return $response;
}
$role = Roles::where('id', $user->role_id)->firstOrFail();
if ($role->name !== "Administrator") {
$response->header(Constants::RESPONSE_HEADER, "Permission are required for performing registration operation.");
$response->setStatusCode(Response::HTTP_FORBIDDEN);
return $response;
}
try {
$roleName = $request->get('roleName');
if ($roleName === null) {
$request->request->set('roleId', $this->retrieveRoleIdByName('Customer'));
} else {
$request->request->set('roleId', $this->retrieveRoleIdByName($roleName));
}
} catch (Exception $exception) {
$response->header(Constants::RESPONSE_HEADER, $exception->getMessage());
$response->setStatusCode(Response::HTTP_BAD_REQUEST);
return $response;
}
return $next($request);
}
示例2: responseFactory
public function responseFactory($content, $code = 200)
{
$response = new Response();
$response->setContent($content);
$response->setStatusCode($code);
return $response;
}
示例3: retrieveUserData
public function retrieveUserData(Request $request, Response $response)
{
if (Auth::check() === false) {
$response->header(Constants::RESPONSE_HEADER, "There is no authenticated user.");
$response->setStatusCode(Response::HTTP_NO_CONTENT);
return $response;
}
$user = Auth::user();
if ($user === null) {
$response->header(Constants::RESPONSE_HEADER, "There is no authenticated user.");
$response->setStatusCode(Response::HTTP_NO_CONTENT);
return $response;
}
Log::debug("Retrieved user data: [" . json_encode($user) . "]");
return $user;
}
示例4: createUser
public function createUser(Request $request, Response $response)
{
$validator = $this->validator($request->all());
if ($validator->fails()) {
$response->header(Constants::RESPONSE_HEADER, "Validation failed with the following error messages: [" . $validator->errors() . "].");
$response->setStatusCode(Response::HTTP_BAD_REQUEST);
return $response;
}
$user = User::create(['email' => $request->input('email'), 'password' => bcrypt($request->input('password')), 'first_name' => $request->input('firstname'), 'last_name' => $request->input('lastname'), 'role_id' => $request->input('roleId'), 'object_name' => $request->input('objectName')]);
if ($user === null) {
$response->header(Constants::RESPONSE_HEADER, "Failed to create user.");
$response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
return $response;
}
return $user;
}
示例5: setResponse
/**
* Preparing Response
*
* @return Response
*/
protected function setResponse()
{
$response = new Response();
$response->setStatusCode($this->content['http_code']);
$response->setContent($this->content);
return $response;
}
示例6: findUserById
public function findUserById(Request $request, Response $response)
{
$validator = Validator::make($request->all(), ['id' => 'required|numeric']);
if ($validator->fails()) {
$response->header(Constants::RESPONSE_HEADER, "\"id\" query parameter is required and must contain number as value.");
$response->setStatusCode(Response::HTTP_UNPROCESSABLE_ENTITY);
return $response;
}
$id = $request->input("id");
$product = User::with('role')->find($id);
if ($product === null) {
$response->header(Constants::RESPONSE_HEADER, "User not found.");
$response->setStatusCode(Response::HTTP_NO_CONTENT);
return $response;
}
$response->header(Constants::RESPONSE_HEADER, "Successfully retrieved data.");
return $product;
}
示例7: sendResponse
/**
* @param Response $response
* @param string $mimeType
*/
protected function sendResponse(Response $response, $mimeType)
{
if (empty($mimeType)) {
$mimeType = 'text/html';
}
$response->header('Content-type', $mimeType);
$response->setStatusCode(404);
$response->send();
exit;
}
示例8: it_doesnt_parse_error_responses
/**
* @test
*/
public function it_doesnt_parse_error_responses()
{
$response = new Response();
$response->setContent('Content');
$response->setStatusCode(500);
$response->headers = new ResponseHeaderBag(['header' => 'value']);
$responseParser = new ResponseParser($response);
$this->assertFalse($responseParser->isCacheable());
$this->assertNull($responseParser->cacheValue());
}
示例9: symfonyAction
public function symfonyAction()
{
$ua = Request::header('User-Agent');
//Redirect to static Masarap page if no User Agent HTTP header was found
if (!preg_match("@Masarap/@", $ua)) {
return File::get(public_path() . '/masarap-symfony/index.html');
}
// end if no Masarap User Agent
$status_code = FORCE_UPDATE_STATUS_CODE;
$data = array('status_code' => $status_code, 'message' => "[{$status_code}] Force Update.", 'app_version' => APP_VERSION, 'app_store' => APP_STORE_LINK, 'google_play' => PLAY_STORE_LINK);
$response = new Response(json_encode($data));
$response->setStatusCode($status_code, "Force Update");
$response->headers->set('Content-Type', 'application/json');
$response->send();
exit;
}
示例10: persistOrder
public function persistOrder(Request $request, Response $response, $requestBody, $user)
{
DB::transaction(function () use(&$response, &$requestBody, &$user) {
$deliveryInfo = new \stdClass();
$deliveryInfo->email = $requestBody->email;
$deliveryInfo->phone = $requestBody->phone;
$deliveryInfo->address = $requestBody->address;
$baseOrderEntry = null;
foreach ($requestBody->products as $product) {
$createdEntry = Orders::create(["user_id" => $user->id, "product_id" => $product->id, "order_date" => date("Y-m-d H:i:s"), "delivery_date" => date("Y-m-d H:i:s"), "is_payed" => 0, "delivery_info" => json_encode($deliveryInfo, JSON_UNESCAPED_UNICODE), "in_order_with" => $baseOrderEntry !== null ? $baseOrderEntry->id : 0, "order_count" => $product->quantity]);
if ($baseOrderEntry === null) {
$baseOrderEntry = $createdEntry;
}
}
$response->header("Content-Type", "application/json");
$response->header(Constants::RESPONSE_HEADER, "Successfully persisted entity.");
$response->setStatusCode(Response::HTTP_CREATED);
});
return $response;
}
示例11: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
//check Server Status
if (SERVER_STATUS === 1) {
$response = new Response();
$status_code = SERVER_MAINTENANCE_STATUS_CODE;
$response->setStatusCode($status_code, "Under Maintenance");
$response->send();
exit;
}
//end of SERVER STATUS CHECK
$ua = $request->headers;
$accept = $request->headers->get('Accept');
$bypass = $request->query("bypass");
if (!$bypass && BYPASS_USER_AGENT_CHECK == 0) {
//Redirect to static Masarap page if no User Agent HTTP header was found
if (!preg_match("@Masarap/@", $ua)) {
return File::get(public_path() . '/masarap-symfony/index.html');
}
// end if no Masarap User Agent
//Check the version in the User Agent for FORCE UPDATE
//Use in Version 1.1 and Up
if (!preg_match("@Masarap/" . APP_VERSION . "@", $ua) && !preg_match("@version=" . SERVER_VERSION . "@", $accept)) {
$status_code = FORCE_UPDATE_STATUS_CODE;
$data = array('status_code' => $status_code, 'message' => "[{$status_code}] Force Update.", 'app_version' => APP_VERSION, 'app_store' => APP_STORE_LINK, 'google_play' => PLAY_STORE_LINK);
$response = new Response(json_encode($data));
$response->setStatusCode($status_code, "Force Update");
$response->headers->set('Content-Type', 'application/json');
$response->send();
exit;
}
// end of pregmatch
}
// end of bypass if
return $next($request);
}
示例12: getDisplayAttachment
/**
* Display an attachment file such as image
*
* @param Project $project
* @param Issue $issue
* @param Attachment $attachment
* @param Request $request
*
* @return Response
*/
public function getDisplayAttachment(Project $project, Issue $issue, Attachment $attachment, Request $request)
{
$issue->setRelation('project', $project);
$attachment->setRelation('issue', $issue);
$path = config('tinyissue.uploads_dir') . '/' . $issue->project_id . '/' . $attachment->upload_token . '/' . $attachment->filename;
$storage = \Storage::disk('local');
$length = $storage->size($path);
$time = $storage->lastModified($path);
$type = $storage->getDriver()->getMimetype($path);
$response = new Response();
$response->setEtag(md5($time . $path));
$response->setExpires(new \DateTime('@' . ($time + 60)));
$response->setLastModified(new \DateTime('@' . $time));
$response->setPublic();
$response->setStatusCode(200);
$response->header('Content-Type', $type);
$response->header('Content-Length', $length);
$response->header('Content-Disposition', 'inline; filename="' . $attachment->filename . '"');
$response->header('Cache-Control', 'must-revalidate');
if ($response->isNotModified($request)) {
// Return empty response if not modified
return $response;
}
// Return file if first request / modified
$response->setContent($storage->get($path));
return $response;
}
示例13: deleteEntity
public function deleteEntity(Request $request, Response $response)
{
$validator = Validator::make($request->all(), ['id' => 'required|numeric']);
if ($validator->fails()) {
$response->header(Constants::RESPONSE_HEADER, "\"id\" query parameter is required and must contain number as value.");
$response->setStatusCode(Response::HTTP_UNPROCESSABLE_ENTITY);
return $response;
}
$id = $request->input("id");
$product = Products::find($id);
DB::beginTransaction();
$isFileDeleted = $this->persistenceHelper->deleteImageByName($product->image_name);
if ($isFileDeleted === false) {
DB::rollBack();
$response->header(Constants::RESPONSE_HEADER, "Failed to delete previous file.");
$response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
return $response;
}
$isProductDeleted = $product->delete();
if ($isProductDeleted === false) {
DB::rollBack();
$response->header(Constants::RESPONSE_HEADER, "Failed to delete previous file.");
$response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
return $response;
}
DB::commit();
$response->header(Constants::RESPONSE_HEADER, "Successfully deleted product entry.");
$response->setStatusCode(Response::HTTP_NO_CONTENT);
return $response;
}
示例14: getRootItems
public function getRootItems(Request $request, Response $response)
{
$items = $this->persistenceHelper->findItemByParentId(1);
if ($items === null) {
$response->header(Constants::RESPONSE_HEADER, "Entity not found.");
$response->setStatusCode(Response::HTTP_NO_CONTENT);
return $response;
}
$response->header(Constants::RESPONSE_HEADER, "Successfully retrieved data.");
return $items;
}
示例15: saveImage
public function saveImage(Response $response, $file)
{
$imageName = round(microtime(true) * 1000) . "." . $file->getClientOriginalExtension();
try {
$file->move(base_path(Constants::IMAGE_PATH), $imageName);
} catch (Exception $exception) {
$response->header(Constants::RESPONSE_HEADER, "Failed to upload image reason: [" . $exception->getMessage() . "]");
$response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
return $response;
}
$response->header("Content-Type", "application/json; charset=UTF-8");
$response->header(Constants::RESPONSE_HEADER, "Successfully uploaded image.");
$response->setStatusCode(Response::HTTP_CREATED);
$response->setContent("{\"imageName\":\"" . $imageName . "\"}");
return $response;
}