当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::setStatusCode方法代码示例

本文整理汇总了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);
 }
开发者ID:JulietaGosheva,项目名称:truck-shop,代码行数:33,代码来源:RegistrationMiddleware.php

示例2: responseFactory

 public function responseFactory($content, $code = 200)
 {
     $response = new Response();
     $response->setContent($content);
     $response->setStatusCode($code);
     return $response;
 }
开发者ID:helpscout,项目名称:specter,代码行数:7,代码来源:IlluminateHttpFactory.php

示例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;
 }
开发者ID:JulietaGosheva,项目名称:truck-shop,代码行数:16,代码来源:UsersController.php

示例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;
 }
开发者ID:JulietaGosheva,项目名称:truck-shop,代码行数:16,代码来源:AuthController.php

示例5: setResponse

 /**
  * Preparing Response
  *
  * @return Response
  */
 protected function setResponse()
 {
     $response = new Response();
     $response->setStatusCode($this->content['http_code']);
     $response->setContent($this->content);
     return $response;
 }
开发者ID:Baasify,项目名称:Baasify,代码行数:12,代码来源:MainController.php

示例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;
 }
开发者ID:JulietaGosheva,项目名称:truck-shop,代码行数:18,代码来源:UserPersistenceHelper.php

示例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;
 }
开发者ID:KodiComponents,项目名称:module-pages,代码行数:14,代码来源:PageNotFoundException.php

示例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());
 }
开发者ID:Waavi,项目名称:responsecache,代码行数:13,代码来源:ResponseParserTest.php

示例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;
 }
开发者ID:jigen7,项目名称:laravel5,代码行数:16,代码来源:ApiController.php

示例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;
 }
开发者ID:JulietaGosheva,项目名称:truck-shop,代码行数:20,代码来源:OrderPersistenceHelper.php

示例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);
 }
开发者ID:jigen7,项目名称:laravel5,代码行数:43,代码来源:FiltersBefore.php

示例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;
 }
开发者ID:oliverpool,项目名称:tinyissue,代码行数:37,代码来源:IssueController.php

示例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;
 }
开发者ID:JulietaGosheva,项目名称:truck-shop,代码行数:30,代码来源:ProductsController.php

示例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;
 }
开发者ID:JulietaGosheva,项目名称:truck-shop,代码行数:11,代码来源:NavigationController.php

示例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;
 }
开发者ID:JulietaGosheva,项目名称:truck-shop,代码行数:16,代码来源:ProductPersistenceHelper.php


注:本文中的Illuminate\Http\Response::setStatusCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。