当前位置: 首页>>代码示例>>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;未经允许,请勿转载。