No Description

GetQueueAttributeResponse.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace AliyunMNS\Responses;
  3. use AliyunMNS\Constants;
  4. use AliyunMNS\Model\QueueAttributes;
  5. use AliyunMNS\Exception\MnsException;
  6. use AliyunMNS\Exception\QueueNotExistException;
  7. use AliyunMNS\Exception\InvalidArgumentException;
  8. use AliyunMNS\Responses\BaseResponse;
  9. use AliyunMNS\Common\XMLParser;
  10. class GetQueueAttributeResponse extends BaseResponse
  11. {
  12. private $attributes;
  13. public function __construct()
  14. {
  15. $this->attributes = NULL;
  16. }
  17. public function getQueueAttributes()
  18. {
  19. return $this->attributes;
  20. }
  21. public function parseResponse($statusCode, $content)
  22. {
  23. $this->statusCode = $statusCode;
  24. if ($statusCode == 200) {
  25. $this->succeed = TRUE;
  26. } else {
  27. $this->parseErrorResponse($statusCode, $content);
  28. }
  29. $xmlReader = $this->loadXmlContent($content);
  30. try {
  31. $this->attributes = QueueAttributes::fromXML($xmlReader);
  32. } catch (\Exception $e) {
  33. throw new MnsException($statusCode, $e->getMessage(), $e);
  34. } catch (\Throwable $t) {
  35. throw new MnsException($statusCode, $t->getMessage());
  36. }
  37. }
  38. public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
  39. {
  40. $this->succeed = FALSE;
  41. $xmlReader = $this->loadXmlContent($content);
  42. try {
  43. $result = XMLParser::parseNormalError($xmlReader);
  44. if ($result['Code'] == Constants::QUEUE_NOT_EXIST)
  45. {
  46. throw new QueueNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  47. }
  48. throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  49. } catch (\Exception $e) {
  50. if ($exception != NULL) {
  51. throw $exception;
  52. } elseif($e instanceof MnsException) {
  53. throw $e;
  54. } else {
  55. throw new MnsException($statusCode, $e->getMessage());
  56. }
  57. } catch (\Throwable $t) {
  58. throw new MnsException($statusCode, $t->getMessage());
  59. }
  60. }
  61. }
  62. ?>