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