當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Response::setCode方法代碼示例

本文整理匯總了PHP中Response::setCode方法的典型用法代碼示例。如果您正苦於以下問題:PHP Response::setCode方法的具體用法?PHP Response::setCode怎麽用?PHP Response::setCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Response的用法示例。


在下文中一共展示了Response::setCode方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: call

 /**
  * @param Request $request
  * @return Response
  */
 public function call(Request $request)
 {
     // Create cURL
     $ch = curl_init();
     // Set-up URL
     curl_setopt($ch, CURLOPT_URL, $request->getUrl());
     // Set-up headers
     $headers = $request->getHeaders();
     array_walk($headers, function (&$item, $key) {
         $item = "{$key}: {$item}";
     });
     curl_setopt($ch, CURLOPT_HTTPHEADER, array_values($headers));
     // Set-up others
     curl_setopt_array($ch, $request->getOpts());
     // Receive result
     $result = curl_exec($ch);
     // Parse response
     $response = new Response();
     if ($result === FALSE) {
         $response->setError(curl_strerror(curl_errno($ch)));
         $response->setData(FALSE);
         $response->setCode(curl_errno($ch));
         $response->setHeaders(curl_getinfo($ch));
     } else {
         $response->setData(json_decode($result));
         $response->setCode(curl_getinfo($ch, CURLINFO_HTTP_CODE));
         $response->setHeaders(curl_getinfo($ch));
     }
     // Close cURL
     curl_close($ch);
     return $response;
 }
開發者ID:r01261,項目名稱:GopayInline,代碼行數:36,代碼來源:Curl.php

示例2: __invoke

 /**
  * @param Request  $req
  * @param Response $res
  *
  * @return Response
  */
 public function __invoke($req, $res)
 {
     if ($req->isHtml()) {
         $res->render(new View('not_found', ['title' => 'Not Found']));
     }
     return $res->setCode(404);
 }
開發者ID:idealistsoft,項目名稱:framework-bootstrap,代碼行數:13,代碼來源:NotFoundHandler.php

示例3: __invoke

 /**
  * @param Request  $req
  * @param Response $res
  * @param array    $allowedMethods
  *
  * @return Response
  */
 public function __invoke($req, $res, $allowedMethods)
 {
     if ($req->isHtml()) {
         $res->render(new View('method_not_allowed', ['title' => 'Method Not Allowed', 'allowedMethods' => $allowedMethods]));
     }
     return $res->setCode(405);
 }
開發者ID:idealistsoft,項目名稱:framework-bootstrap,代碼行數:14,代碼來源:MethodNotAllowedHandler.php

示例4: __invoke

 /**
  * @param Request    $req
  * @param Response   $res
  * @param \Exception $e
  *
  * @return Response
  */
 public function __invoke($req, $res, \Exception $e)
 {
     $this->app['logger']->error('An uncaught exception occurred while handling a request.', ['exception' => $e]);
     if ($req->isHtml()) {
         $res->render(new View('exception', ['title' => 'Internal Server Error', 'exception' => $e]));
     }
     return $res->setCode(500);
 }
開發者ID:idealistsoft,項目名稱:framework-bootstrap,代碼行數:15,代碼來源:ExceptionHandler.php

示例5: createResponse

 /**
  * {@inheritdoc}
  * @see \InoOicClient\Oic\Authorization\ResponseFactoryInterface::createResponse()
  */
 public function createResponse($code, $state = null)
 {
     $response = new Response();
     $response->setCode($code);
     if (null !== $state) {
         $response->setState($state);
     }
     return $response;
 }
開發者ID:publicitas-deployment,項目名稱:php-openid-connect-client,代碼行數:13,代碼來源:ResponseFactory.php

示例6: report

 /**
  *
  * Report the error
  *
  * @param [string] The message to be displayed
  * @param [boolean] Whether or not to display PHP backtrace
  */
 function report($msg, $backtrace = true)
 {
     // Check for error reporting flag
     if ($this->config['error_reporting']) {
         Template::load('error_reporting.html', array("msg" => $msg, "backtrace" => print_r(debug_backtrace(), true)));
         exit;
     } else {
         // Prepare 404 response
         $Response = new Response();
         $Response->setCode(404);
         $Response->send();
         Template::load('404.html');
     }
     exit;
 }
開發者ID:nunodotferreira,項目名稱:Ratchet,代碼行數:22,代碼來源:Errors.php

示例7: createAction

 /**
  * @route POST /?method=users.create&format=json
  * @route POST /users/create.json
  * 
  * @param Request $request
  * @return Response
  * @throws Exception
  */
 public function createAction($request)
 {
     $request->acceptContentTypes(array('json'));
     if ('POST' != $request->getMethod()) {
         throw new Exception('HTTP method not allowed', Response::NOT_ALLOWED);
     }
     try {
         $user = new User(array('name' => $request->getPost('name'), 'username' => $request->getPost('username'), 'email' => $request->getPost('email'), 'gender' => $request->getPost('gender')));
     } catch (ValidationException $e) {
         throw new Exception($e->getMessage(), Response::OK);
     }
     $id = $this->getModel('User')->save($user);
     if (!is_numeric($id)) {
         throw new Exception('An error occurred while creating user', Response::OK);
     }
     $response = new Response();
     $response->setCode(Response::CREATED);
     $response->setEtagHeader(md5('/users/' . $id));
     return $response;
 }
開發者ID:sayi21cn,項目名稱:apify-library,代碼行數:28,代碼來源:UsersController.php

示例8: runApp

 public static function runApp()
 {
     if (!Request::isАuthorized()) {
         Response::setCode(401);
         return;
     }
     $matchedResource = Router::getMatchedRouterResource(Request::getMethod(), Request::getCleanRequestUrl());
     if ($matchedResource === null) {
         Response::setCode(404);
         return;
     }
     try {
         $response = self::executeResoruceAction($matchedResource[0], $matchedResource[1], Router::getMachedRouteParameters());
         if ($response === false) {
             Response::setCode(404);
         } else {
             Response::setBody($response);
         }
     } catch (\Exception $e) {
         Response::setCode(500);
     }
 }
開發者ID:pavel-tashev,項目名稱:APIJet,代碼行數:22,代碼來源:APIJet.php

示例9: buildTransferReversal

 private function buildTransferReversal($xml)
 {
     $transferReversal = new TransferReversal();
     $transferReversal->setRequestId((string) $xml->RequestId);
     $transferReversal->setOriginalRequestId((string) $xml->OriginalRequestId);
     $transferReversal->setTransactionReference((string) $xml->TransactionReference);
     $transactionHistory = new TransactionHistory();
     $tmpTransaction = new Transaction();
     $transaction = $xml->TransactionHistory->Transaction;
     $tmpTransaction->setType((string) $transaction->Type);
     $tmpTransaction->setSystemTraceAuditNumber((string) $transaction->SystemTraceAuditNumber);
     $tmpTransaction->setNetworkReferenceNumber((string) $transaction->NetworkReferenceNumber);
     $tmpTransaction->setSettlementDate((string) $transaction->SettlementDate);
     $tmpResponse = new Response();
     $response = $transaction->Response;
     $tmpResponse->setCode((string) $response->Code);
     $tmpResponse->setDescription((string) $response->Description);
     $tmpTransaction->setSubmitDateTime((string) $transaction->SubmitDateTime);
     $tmpTransaction->setResponse($tmpResponse);
     $transactionHistory->setTransaction($tmpTransaction);
     $transferReversal->setTransactionHistory($transactionHistory);
     return $transferReversal;
 }
開發者ID:payene,項目名稱:mastercard-api-php,代碼行數:23,代碼來源:TransferReversalService.php

示例10: redirect

 /**
  * @param string $uri
  * @param integer $code HTTP status codes
  * @return void
  */
 public function redirect($uri, $code = Response::FOUND)
 {
     $response = new Response();
     $response->setCode($code);
     $response->addHeader('Location: ' . $uri);
     $response->sendHeaders();
     exit;
 }
開發者ID:sayi21cn,項目名稱:apify-library,代碼行數:13,代碼來源:Request.php

示例11: buildTransfer

 private function buildTransfer($xml)
 {
     $transfer = new Transfer();
     $transfer->setRequestId((string) $xml->RequestId);
     $transfer->setTransactionReference((string) $xml->TransactionReference);
     $transactionHistory = new TransactionHistory();
     $transactionArray = array();
     foreach ($xml->TransactionHistory->Transaction as $transaction) {
         $tmpTransaction = new Transaction();
         $tmpTransaction->setType((string) $transaction->Type);
         $tmpTransaction->setSystemTraceAuditNumber((string) $transaction->SystemTraceAuditNumber);
         $tmpTransaction->setNetworkReferenceNumber((string) $transaction->NetworkReferenceNumber);
         $tmpTransaction->setSettlementDate((string) $transaction->SettlementDate);
         $tmpResponse = new Response();
         $response = $transaction->Response;
         $tmpResponse->setCode((string) $response->Code);
         $tmpResponse->setDescription((string) $response->Description);
         $tmpTransaction->setSubmitDateTime((string) $transaction->SubmitDateTime);
         $tmpTransaction->setResponse($tmpResponse);
         array_push($transactionArray, $tmpTransaction);
     }
     $transactionHistory->setTransaction($transactionArray);
     $transfer->setTransactionHistory($transactionHistory);
     return $transfer;
 }
開發者ID:payene,項目名稱:mastercard-api-php,代碼行數:25,代碼來源:TransferService.php

示例12: setResponseCode

 public function setResponseCode($code)
 {
     Response::setCode($code);
 }
開發者ID:pavel-tashev,項目名稱:APIJet,代碼行數:4,代碼來源:BaseController.php


注:本文中的Response::setCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。