ResponseCore.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace OSS\Http;
  3. /**
  4. * Container for all response-related methods.
  5. */
  6. class ResponseCore
  7. {
  8. /**
  9. * Store the HTTP header information.
  10. */
  11. public $header;
  12. /**
  13. * Store the SimpleXML response.
  14. */
  15. public $body;
  16. /**
  17. * Store the HTTP response code.
  18. */
  19. public $status;
  20. /**
  21. * Construct a new instance of this class.
  22. *
  23. * @param array $header (Required) Associative array of HTTP headers (typically returned by <RequestCore::get_response_header()>).
  24. * @param string $body (Required) XML-formatted response from OSS.
  25. * @param integer $status (Optional) HTTP response status code from the request.
  26. * @return Mixed Contains an <php:array> `header` property (HTTP headers as an associative array), a <php:SimpleXMLElement> or <php:string> `body` property, and an <php:integer> `status` code.
  27. */
  28. public function __construct($header, $body, $status = null)
  29. {
  30. $this->header = $header;
  31. $this->body = $body;
  32. $this->status = $status;
  33. return $this;
  34. }
  35. /**
  36. * Did we receive the status code we expected?
  37. *
  38. * @param integer|array $codes (Optional) The status code(s) to expect. Pass an <php:integer> for a single acceptable value, or an <php:array> of integers for multiple acceptable values.
  39. * @return boolean Whether we received the expected status code or not.
  40. */
  41. public function isOK($codes = array(200, 201, 204, 206))
  42. {
  43. if (is_array($codes)) {
  44. return in_array($this->status, $codes);
  45. }
  46. return $this->status === $codes;
  47. }
  48. }