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


PHP Response::status方法代碼示例

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


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

示例1: on_header_location

 /**
  * The default handler for following redirects, triggered by the presence of
  * a Location header in the response.
  *
  * The client's follow property must be set TRUE and the HTTP response status
  * one of 201, 301, 302, 303 or 307 for the redirect to be followed.
  *
  * @param Request        $request
  * @param Response       $response
  * @param Request_Client $client
  */
 public static function on_header_location(Request $request, Response $response, Request_Client $client)
 {
     // Do we need to follow a Location header ?
     if ($client->follow() and in_array($response->status(), [201, 301, 302, 303, 307])) {
         // Figure out which method to use for the follow request
         switch ($response->status()) {
             default:
             case 301:
             case 307:
                 $follow_method = $request->method();
                 break;
             case 201:
             case 303:
                 $follow_method = Request::GET;
                 break;
             case 302:
                 // Cater for sites with broken HTTP redirect implementations
                 if ($client->strict_redirect()) {
                     $follow_method = $request->method();
                 } else {
                     $follow_method = Request::GET;
                 }
                 break;
         }
         // Prepare the additional request, copying any follow_headers that were present on the original request
         $orig_headers = $request->headers()->getArrayCopy();
         $follow_headers = array_intersect_assoc($orig_headers, array_fill_keys($client->follow_headers(), true));
         $follow_request = Request::factory($response->headers('Location'))->method($follow_method)->headers($follow_headers);
         if ($follow_method !== Request::GET) {
             $follow_request->body($request->body());
         }
         return $follow_request;
     }
     return null;
 }
開發者ID:s4urp8n,項目名稱:kohana-admin,代碼行數:46,代碼來源:Client.php

示例2: testStatusShouldUsePredefinedReasonPhrasesForMatchingStatusCodes

 public function testStatusShouldUsePredefinedReasonPhrasesForMatchingStatusCodes()
 {
     $response = new Response();
     $response->status(404);
     $this->assertEquals('404 Not Found', $response->status());
     $response->status(405);
     $this->assertEquals('405 Method Not Allowed', $response->status());
 }
開發者ID:holger,項目名稱:yoshi,代碼行數:8,代碼來源:ResponseTest.php

示例3: parse_response

 /**
  * Parses a response from the Codebase API and returns the results as an array,
  * if the response contains any errors an exception is thrown
  *
  * @param	Response			$response
  * @return	array
  * @throws	Codebase_Exception
  * @static
  */
 protected static function parse_response(Response $response)
 {
     if ($response->status() >= 400) {
         throw new Codebase_Exception('HTTP ' . $response->status() . ' error');
     }
     $parsed_result = new SimpleXMLElement($response->body());
     // check for errors?
     return $parsed_result;
 }
開發者ID:rpa-design,項目名稱:codebase,代碼行數:18,代碼來源:core.php

示例4: _send_message

 /**
  * Sends the HTTP message [Request] to a remote server and processes
  * the response.
  *
  * @param   Request   $request  request to send
  * @param   Response  $request  response to send
  * @return  Response
  */
 public function _send_message(Request $request, Response $response)
 {
     // Response headers
     $response_headers = array();
     $options = array();
     // Set the request method
     $options = $this->_set_curl_request_method($request, $options);
     // Set the request body. This is perfectly legal in CURL even
     // if using a request other than POST. PUT does support this method
     // and DOES NOT require writing data to disk before putting it, if
     // reading the PHP docs you may have got that impression. SdF
     // This will also add a Content-Type: application/x-www-form-urlencoded header unless you override it
     if ($body = $request->body()) {
         $options[CURLOPT_POSTFIELDS] = $request->body();
     }
     // Process headers
     if ($headers = $request->headers()) {
         $http_headers = array();
         foreach ($headers as $key => $value) {
             $http_headers[] = $key . ': ' . $value;
         }
         $options[CURLOPT_HTTPHEADER] = $http_headers;
     }
     // Process cookies
     if ($cookies = $request->cookie()) {
         $options[CURLOPT_COOKIE] = http_build_query($cookies, NULL, '; ');
     }
     // Get any exisiting response headers
     $response_header = $response->headers();
     // Implement the standard parsing parameters
     $options[CURLOPT_HEADERFUNCTION] = array($response_header, 'parse_header_string');
     $this->_options[CURLOPT_RETURNTRANSFER] = TRUE;
     $this->_options[CURLOPT_HEADER] = FALSE;
     // Apply any additional options set to
     $options += $this->_options;
     $uri = $request->uri();
     if ($query = $request->query()) {
         $uri .= '?' . http_build_query($query, NULL, '&');
     }
     // Open a new remote connection
     $curl = curl_init($uri);
     // Set connection options
     if (!curl_setopt_array($curl, $options)) {
         throw new Request_Exception('Failed to set CURL options, check CURL documentation: :url', array(':url' => 'http://php.net/curl_setopt_array'));
     }
     // Get the response body
     $body = curl_exec($curl);
     // Get the response information
     $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     if ($body === FALSE) {
         $error = curl_error($curl);
     }
     // Close the connection
     curl_close($curl);
     if (isset($error)) {
         throw new Request_Exception('Error fetching remote :url [ status :code ] :error', array(':url' => $request->url(), ':code' => $code, ':error' => $error));
     }
     $response->status($code)->body($body);
     return $response;
 }
開發者ID:creat2012,項目名稱:hustoj_official,代碼行數:68,代碼來源:Curl.php

示例5: handle

 public static function handle(Exception $e)
 {
     switch (get_class($e)) {
         case 'HTTP_Exception_404':
             $response = new Response();
             $response->status(404);
             $view = new View('errors/error404');
             Controller_Abstract::add_static();
             if (Kohana::$environment == Kohana::DEVELOPMENT) {
                 $view->message = $e->getMessage();
             }
             echo $response->body($view)->send_headers()->body();
             return TRUE;
             break;
         case 'HTTP_Exception_410':
             $response = new Response();
             $response->status(410);
             $view = new View('errors/error410');
             Controller_Abstract::add_static();
             echo $response->body($view)->send_headers()->body();
             return TRUE;
             break;
         default:
             header('C-Data: ' . uniqid() . str_replace('=', '', base64_encode($e->getMessage())));
             return Kohana_Exception::handler($e);
             break;
     }
 }
開發者ID:nergal,項目名稱:2mio,代碼行數:28,代碼來源:handler.php

示例6: handle

 public static function handle(Exception $e)
 {
     switch (get_class($e)) {
         case 'HTTP_Exception_404':
             // Посылаем статус страницы 404
             $response = new Response();
             $response->status(404);
             $response->protocol('HTTP/1.1');
             // Посылаем корректный статус 404 ошибки
             /* header('HTTP/1.0 404 Not Found');
                header('HTTP/1.1 404 Not Found');
                header('Status: 404 Not Found'); */
             // Создаем вид для отображения 404 ошибки
             $view = new View_Error_404('error/404');
             $view->message = $e->getMessage();
             // Если шаблон есть - отображаем страницу ошибки
             if (!empty($view)) {
                 // Выводим шаблон
                 echo $response->send_headers()->body($view->render());
             } else {
                 echo $response->body('<h1>Не найден шаблон для View_Error_404</h1>');
             }
             return true;
             break;
         default:
             Kohana_Exception::handler($e);
     }
 }
開發者ID:bosoy83,項目名稱:progtest,代碼行數:28,代碼來源:exceptionhandler.php

示例7: _send_message

 /**
  * Sends the HTTP message [Request] to a remote server and processes
  * the response.
  *
  * @param   Request   $request  request to send
  * @param   Response  $request  response to send
  * @return  Response
  */
 public function _send_message(Request $request, Response $response)
 {
     $http_method_mapping = array(HTTP_Request::GET => HTTPRequest::METH_GET, HTTP_Request::HEAD => HTTPRequest::METH_HEAD, HTTP_Request::POST => HTTPRequest::METH_POST, HTTP_Request::PUT => HTTPRequest::METH_PUT, HTTP_Request::DELETE => HTTPRequest::METH_DELETE, HTTP_Request::OPTIONS => HTTPRequest::METH_OPTIONS, HTTP_Request::TRACE => HTTPRequest::METH_TRACE, HTTP_Request::CONNECT => HTTPRequest::METH_CONNECT);
     // Create an http request object
     $http_request = new HTTPRequest($request->uri(), $http_method_mapping[$request->method()]);
     if ($this->_options) {
         // Set custom options
         $http_request->setOptions($this->_options);
     }
     // Set headers
     $http_request->setHeaders($request->headers()->getArrayCopy());
     // Set cookies
     $http_request->setCookies($request->cookie());
     // Set query data (?foo=bar&bar=foo)
     $http_request->setQueryData($request->query());
     // Set the body
     if ($request->method() == HTTP_Request::PUT) {
         $http_request->addPutData($request->body());
     } else {
         $http_request->setBody($request->body());
     }
     try {
         $http_request->send();
     } catch (HTTPRequestException $e) {
         throw new Request_Exception($e->getMessage());
     } catch (HTTPMalformedHeaderException $e) {
         throw new Request_Exception($e->getMessage());
     } catch (HTTPEncodingException $e) {
         throw new Request_Exception($e->getMessage());
     }
     // Build the response
     $response->status($http_request->getResponseCode())->headers($http_request->getResponseHeader())->cookie($http_request->getResponseCookies())->body($http_request->getResponseBody());
     return $response;
 }
開發者ID:artbypravesh,項目名稱:morningpages,代碼行數:42,代碼來源:HTTP.php

示例8: error

 public static function error($message, $status = 501)
 {
     Event::trigger('api.error', [$message, $status]);
     Response::status($status);
     Response::json(['error' => ['type' => 'fatal', 'status' => $status, 'message' => $message]]);
     Response::send();
     exit;
 }
開發者ID:caffeina-core,項目名稱:api,代碼行數:8,代碼來源:API.php

示例9: handler

 /**
  * Inline exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses    Kohana_Exception::text
  * @param   object   exception object
  * @return  boolean
  */
 public static function handler(Exception $e)
 {
     $response = new Response();
     switch (get_class($e)) {
         case 'HTTP_Exception_404':
             $view = new View_Error_404();
             $view->message = $e->getMessage();
             $response->status(404);
             $view->title = 'File Not Found';
             break;
         default:
             $view = new View_Error_500();
             $view->message = $e->getMessage();
             $response->status(500);
             $view->title = 'NOMNOMNOMN';
             break;
     }
     echo $response->body($view)->send_headers()->body();
 }
開發者ID:kohana,項目名稱:kohanaframework.org,代碼行數:27,代碼來源:exception.php

示例10: handle

 public static function handle(Exception $e)
 {
     switch (get_class($e)) {
         case 'HTTP_Exception_404':
             $response = new Response();
             $response->status(404);
             $request = Request::factory('404error')->method(Request::POST)->post(array('message' => $e->getMessage()))->execute();
             echo $response->body($request)->send_headers()->body();
             return TRUE;
             break;
         default:
             return Kohana_Exception::handler($e);
             break;
     }
 }
開發者ID:Alexander711,項目名稱:naav1,代碼行數:15,代碼來源:exceptionhandler.php

示例11: handler

 /**
  * Overriden to show custom page for 404 errors
  */
 public static function handler(Exception $e)
 {
     switch (get_class($e)) {
         case 'HTTP_Exception_404':
             $response = new Response();
             $response->status(404);
             //  $view = new View('errors/report');
             // $view->message = $e->getMessage();
             echo $response->body("<h2>Page Not Found</h2> <a href=\"/\" >Go Home</a>")->send_headers()->body();
             return TRUE;
             break;
         default:
             return Kohana_Kohana_Exception::handler($e);
             break;
     }
 }
開發者ID:kanikaN,項目名稱:qload,代碼行數:19,代碼來源:exception.php

示例12: handle

 public static function handle(Exception $e)
 {
     switch (get_class($e)) {
         case 'Http_Exception_404':
             $response = new Response();
             $response->status(404);
             $view = new View('404view');
             $view->message = $e->getMessage();
             echo $response->body($view)->send_headers()->body();
             return TRUE;
             break;
         default:
             return Kohana_Exception::handler($e);
             break;
     }
 }
開發者ID:sysdevbol,項目名稱:entidad,代碼行數:16,代碼來源:exceptionhandler.php

示例13: performCommonAssertionsAndGetRecords

 /**
  * Utility function to drilldown to the records returned by the request
  * 
  * @param Response $response
  * @param string|null $modelShortName
  * @param int $code
  * @return array
  */
 protected function performCommonAssertionsAndGetRecords($response, $modelShortName = null, $code = 200)
 {
     if (!$modelShortName) {
         $modelShortName = $this->buildModelShortName();
     }
     $responseData = json_decode($response->body(), true);
     // perform the status assertion after we get the body. sometimes it's helpful
     // during debugging to inspect the $responseData without being short-circuited
     // by the failure on the status test
     $this->assertEquals($code, $response->status());
     $this->assertInternalType('array', $responseData);
     $this->assertArrayHasKey($modelShortName, $responseData);
     $records = $responseData[$modelShortName];
     $this->assertInternalType('array', $records);
     return $records;
 }
開發者ID:dwsla,項目名稱:deal,代碼行數:24,代碼來源:AbstractControllerTest.php

示例14: _send_message

 /**
  * Sends the HTTP message [Request] to a remote server and processes
  * the response.
  *
  * @param   Request   $request  request to send
  * @param   Response  $request  response to send
  * @return  Response
  * @uses    [PHP cURL](http://php.net/manual/en/book.curl.php)
  */
 public function _send_message(Request $request, Response $response)
 {
     // Calculate stream mode
     $mode = $request->method() === HTTP_Request::GET ? 'r' : 'r+';
     // Process cookies
     if ($cookies = $request->cookie()) {
         $request->headers('cookie', http_build_query($cookies, NULL, '; '));
     }
     // Get the message body
     $body = $request->body();
     if (is_resource($body)) {
         $body = stream_get_contents($body);
     }
     // Set the content length
     $request->headers('content-length', (string) strlen($body));
     list($protocol) = explode('/', $request->protocol());
     // Create the context
     $options = array(strtolower($protocol) => array('method' => $request->method(), 'header' => (string) $request->headers(), 'content' => $body));
     // Create the context stream
     $context = stream_context_create($options);
     stream_context_set_option($context, $this->_options);
     $uri = $request->uri();
     if ($query = $request->query()) {
         $uri .= '?' . http_build_query($query, NULL, '&');
     }
     $stream = fopen($uri, $mode, FALSE, $context);
     $meta_data = stream_get_meta_data($stream);
     // Get the HTTP response code
     $http_response = array_shift($meta_data['wrapper_data']);
     if (preg_match_all('/(\\w+\\/\\d\\.\\d) (\\d{3})/', $http_response, $matches) !== FALSE) {
         $protocol = $matches[1][0];
         $status = (int) $matches[2][0];
     } else {
         $protocol = NULL;
         $status = NULL;
     }
     // Get any exisiting response headers
     $response_header = $response->headers();
     // Process headers
     array_map(array($response_header, 'parse_header_string'), array(), $meta_data['wrapper_data']);
     $response->status($status)->protocol($protocol)->body(stream_get_contents($stream));
     // Close the stream after use
     fclose($stream);
     return $response;
 }
開發者ID:robert-kampas,項目名稱:games-collection-manager,代碼行數:54,代碼來源:Stream.php

示例15: __construct

 /**
  * 構造函數
  *+-----------------------
  * @param Request $request
  * @param Arry $routes
  * @return Void
  */
 public function __construct(Request &$request, Response &$response, $routes)
 {
     $file = $this->mapPath($routes);
     $rc = new ReflectionClass($this->controller);
     if (!$rc->isAbstract() && $rc->isSubclassOf('Controller')) {
         $controller = new $this->controller($request);
         if (method_exists($controller, $this->action)) {
             ob_start();
             $this->invoke($controller);
             $content = ob_get_contents();
             ob_end_clean();
             $response->body($content);
             $response->status(200);
             return true;
         }
     }
     throw new Ada_Exception('The requested URL was not found on this server');
 }
開發者ID:adawongframework,項目名稱:project,代碼行數:25,代碼來源:Internal.php


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