GuzzleHttpPsr7Response

PSR-7 response implementation.

Defined (1)

The class is defined in the following location(s).

/lib/Azure/GuzzleHttp/Psr7/Response.php  
  1. class Response implements ResponseInterface 
  2. use MessageTrait; 
  3.  
  4. /** @var array Map of standard HTTP status code/reason phrases */ 
  5. private static $phrases = [ 
  6. 100 => 'Continue',  
  7. 101 => 'Switching Protocols',  
  8. 102 => 'Processing',  
  9. 200 => 'OK',  
  10. 201 => 'Created',  
  11. 202 => 'Accepted',  
  12. 203 => 'Non-Authoritative Information',  
  13. 204 => 'No Content',  
  14. 205 => 'Reset Content',  
  15. 206 => 'Partial Content',  
  16. 207 => 'Multi-status',  
  17. 208 => 'Already Reported',  
  18. 300 => 'Multiple Choices',  
  19. 301 => 'Moved Permanently',  
  20. 302 => 'Found',  
  21. 303 => 'See Other',  
  22. 304 => 'Not Modified',  
  23. 305 => 'Use Proxy',  
  24. 306 => 'Switch Proxy',  
  25. 307 => 'Temporary Redirect',  
  26. 400 => 'Bad Request',  
  27. 401 => 'Unauthorized',  
  28. 402 => 'Payment Required',  
  29. 403 => 'Forbidden',  
  30. 404 => 'Not Found',  
  31. 405 => 'Method Not Allowed',  
  32. 406 => 'Not Acceptable',  
  33. 407 => 'Proxy Authentication Required',  
  34. 408 => 'Request Time-out',  
  35. 409 => 'Conflict',  
  36. 410 => 'Gone',  
  37. 411 => 'Length Required',  
  38. 412 => 'Precondition Failed',  
  39. 413 => 'Request Entity Too Large',  
  40. 414 => 'Request-URI Too Large',  
  41. 415 => 'Unsupported Media Type',  
  42. 416 => 'Requested range not satisfiable',  
  43. 417 => 'Expectation Failed',  
  44. 418 => 'I\'m a teapot',  
  45. 422 => 'Unprocessable Entity',  
  46. 423 => 'Locked',  
  47. 424 => 'Failed Dependency',  
  48. 425 => 'Unordered Collection',  
  49. 426 => 'Upgrade Required',  
  50. 428 => 'Precondition Required',  
  51. 429 => 'Too Many Requests',  
  52. 431 => 'Request Header Fields Too Large',  
  53. 451 => 'Unavailable For Legal Reasons',  
  54. 500 => 'Internal Server Error',  
  55. 501 => 'Not Implemented',  
  56. 502 => 'Bad Gateway',  
  57. 503 => 'Service Unavailable',  
  58. 504 => 'Gateway Time-out',  
  59. 505 => 'HTTP Version not supported',  
  60. 506 => 'Variant Also Negotiates',  
  61. 507 => 'Insufficient Storage',  
  62. 508 => 'Loop Detected',  
  63. 511 => 'Network Authentication Required',  
  64. ]; 
  65.  
  66. /** @var string */ 
  67. private $reasonPhrase = ''; 
  68.  
  69. /** @var int */ 
  70. private $statusCode = 200; 
  71.  
  72. /** 
  73. * @param int $status Status code 
  74. * @param array $headers Response headers 
  75. * @param string|null|resource|StreamInterface $body Response body 
  76. * @param string $version Protocol version 
  77. * @param string|null $reason Reason phrase (when empty a default will be used based on the status code) 
  78. */ 
  79. public function __construct( 
  80. $status = 200,  
  81. array $headers = [],  
  82. $body = null,  
  83. $version = '1.1',  
  84. $reason = null 
  85. ) { 
  86. $this->statusCode = (int) $status; 
  87.  
  88. if ($body !== '' && $body !== null) { 
  89. $this->stream = stream_for($body); 
  90.  
  91. $this->setHeaders($headers); 
  92. if ($reason == '' && isset(self::$phrases[$this->statusCode])) { 
  93. $this->reasonPhrase = self::$phrases[$status]; 
  94. } else { 
  95. $this->reasonPhrase = (string) $reason; 
  96.  
  97. $this->protocol = $version; 
  98.  
  99. public function getStatusCode() 
  100. return $this->statusCode; 
  101.  
  102. public function getReasonPhrase() 
  103. return $this->reasonPhrase; 
  104.  
  105. public function withStatus($code, $reasonPhrase = '') 
  106. $new = clone $this; 
  107. $new->statusCode = (int) $code; 
  108. if ($reasonPhrase == '' && isset(self::$phrases[$new->statusCode])) { 
  109. $reasonPhrase = self::$phrases[$new->statusCode]; 
  110. $new->reasonPhrase = $reasonPhrase; 
  111. return $new;