recess-http
[ class tree: recess-http ] [ index: recess-http ] [ all elements ]

Source for file HttpStatusCodes.php

Documentation is available at HttpStatusCodes.php

  1. <?php
  2. /**
  3.  * StatusCodes provides named constants for
  4.  * HTTP protocol status codes. Written for the
  5.  * Recess Framework (http://www.recessframework.com/)
  6.  * 
  7.  * @author Kris Jordan
  8.  * @license MIT
  9.  * @package recess.http
  10.  */
  11. class HttpStatusCodes {
  12.     // [Informational 1xx]
  13.     const HTTP_CONTINUE 100;
  14.     const HTTP_SWITCHING_PROTOCOLS 101;
  15.     // [Successful 2xx]
  16.     const HTTP_OK 200;
  17.     const HTTP_CREATED 201;
  18.     const HTTP_ACCEPTED 202;
  19.     const HTTP_NONAUTHORITATIVE_INFORMATION 203;
  20.     const HTTP_NO_CONTENT 204;
  21.     const HTTP_RESET_CONTENT 205;
  22.     const HTTP_PARTIAL_CONTENT 206;
  23.     // [Redirection 3xx]
  24.     const HTTP_MULTIPLE_CHOICES 300;
  25.     const HTTP_MOVED_PERMANENTLY 301;
  26.     const HTTP_FOUND 302;
  27.     const HTTP_SEE_OTHER 303;
  28.     const HTTP_NOT_MODIFIED 304;
  29.     const HTTP_USE_PROXY 305;
  30.     const HTTP_UNUSED306;
  31.     const HTTP_TEMPORARY_REDIRECT 307;
  32.     // [Client Error 4xx]
  33.     const errorCodesBeginAt 400;
  34.     const HTTP_BAD_REQUEST 400;
  35.     const HTTP_UNAUTHORIZED  401;
  36.     const HTTP_PAYMENT_REQUIRED 402;
  37.     const HTTP_FORBIDDEN 403;
  38.     const HTTP_NOT_FOUND 404;
  39.     const HTTP_METHOD_NOT_ALLOWED 405;
  40.     const HTTP_NOT_ACCEPTABLE 406;
  41.     const HTTP_PROXY_AUTHENTICATION_REQUIRED 407;
  42.     const HTTP_REQUEST_TIMEOUT 408;
  43.     const HTTP_CONFLICT 409;
  44.     const HTTP_GONE 410;
  45.     const HTTP_LENGTH_REQUIRED 411;
  46.     const HTTP_PRECONDITION_FAILED 412;
  47.     const HTTP_REQUEST_ENTITY_TOO_LARGE 413;
  48.     const HTTP_REQUEST_URI_TOO_LONG 414;
  49.     const HTTP_UNSUPPORTED_MEDIA_TYPE 415;
  50.     const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE 416;
  51.     const HTTP_EXPECTATION_FAILED 417;
  52.     // [Server Error 5xx]
  53.     const HTTP_INTERNAL_SERVER_ERROR 500;
  54.     const HTTP_NOT_IMPLEMENTED 501;
  55.     const HTTP_BAD_GATEWAY 502;
  56.     const HTTP_SERVICE_UNAVAILABLE 503;
  57.     const HTTP_GATEWAY_TIMEOUT 504;
  58.     const HTTP_VERSION_NOT_SUPPORTED 505;
  59.         
  60.     private static $messages array(
  61.         // [Informational 1xx]
  62.         100=>'100 Continue',
  63.         101=>'101 Switching Protocols',
  64.         // [Successful 2xx]
  65.         200=>'200 OK',
  66.         201=>'201 Created',
  67.         202=>'202 Accepted',
  68.         203=>'203 Non-Authoritative Information',
  69.         204=>'204 No Content',
  70.         205=>'205 Reset Content',
  71.         206=>'206 Partial Content',
  72.         // [Redirection 3xx]
  73.         300=>'300 Multiple Choices',
  74.         301=>'301 Moved Permanently',
  75.         302=>'302 Found',
  76.         303=>'303 See Other',
  77.         304=>'304 Not Modified',
  78.         305=>'305 Use Proxy',
  79.         306=>'306 (Unused)',
  80.         307=>'307 Temporary Redirect',
  81.         // [Client Error 4xx]
  82.         400=>'400 Bad Request',
  83.         401=>'401 Unauthorized',
  84.         402=>'402 Payment Required',
  85.         403=>'403 Forbidden',
  86.         404=>'404 Not Found',
  87.         405=>'405 Method Not Allowed',
  88.         406=>'406 Not Acceptable',
  89.         407=>'407 Proxy Authentication Required',
  90.         408=>'408 Request Timeout',
  91.         409=>'409 Conflict',
  92.         410=>'410 Gone',
  93.         411=>'411 Length Required',
  94.         412=>'412 Precondition Failed',
  95.         413=>'413 Request Entity Too Large',
  96.         414=>'414 Request-URI Too Long',
  97.         415=>'415 Unsupported Media Type',
  98.         416=>'416 Requested Range Not Satisfiable',
  99.         417=>'417 Expectation Failed',
  100.         // [Server Error 5xx]
  101.         500=>'500 Internal Server Error',
  102.         501=>'501 Not Implemented',
  103.         502=>'502 Bad Gateway',
  104.         503=>'503 Service Unavailable',
  105.         504=>'504 Gateway Timeout',
  106.         505=>'505 HTTP Version Not Supported'
  107.     );
  108.     
  109.     public static function httpHeaderFor($code{
  110.         return 'HTTP/1.1 ' static::$messages[$code];
  111.     }
  112.     public static function getMessageForCode($code{
  113.         return static::$messages[$code];
  114.     }
  115.     
  116.     public static function isError($code{
  117.         return is_numeric($code&& $code >= static::HTTP_BAD_REQUEST;
  118.     }
  119.     
  120.     public static function canHaveBody($code{
  121.         return
  122.             // True if not in 100s
  123.             ($code static::HTTP_CONTINUE || $code >= static::HTTP_OK)
  124.             && // and not 204 NO CONTENT
  125.             $code != static::HTTP_NO_CONTENT
  126.             && // and not 304 NOT MODIFIED
  127.             $code != static::HTTP_NOT_MODIFIED;
  128.     }
  129. }

Documentation generated on Wed, 29 Jul 2015 13:56:41 +0000 by phpDocumentor 1.5.0-lsces