No Description

ListQueueResponse.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace AliyunMNS\Responses;
  3. use AliyunMNS\Exception\MnsException;
  4. use AliyunMNS\Responses\BaseResponse;
  5. use AliyunMNS\Common\XMLParser;
  6. class ListQueueResponse extends BaseResponse
  7. {
  8. private $queueNames;
  9. private $nextMarker;
  10. public function __construct()
  11. {
  12. $this->queueNames = array();
  13. $this->nextMarker = NULL;
  14. }
  15. public function isFinished()
  16. {
  17. return $this->nextMarker == NULL;
  18. }
  19. public function getQueueNames()
  20. {
  21. return $this->queueNames;
  22. }
  23. public function getNextMarker()
  24. {
  25. return $this->nextMarker;
  26. }
  27. public function parseResponse($statusCode, $content)
  28. {
  29. $this->statusCode = $statusCode;
  30. if ($statusCode != 200) {
  31. $this->parseErrorResponse($statusCode, $content);
  32. return;
  33. }
  34. $this->succeed = TRUE;
  35. $xmlReader = $this->loadXmlContent($content);
  36. try {
  37. while ($xmlReader->read())
  38. {
  39. if ($xmlReader->nodeType == \XMLReader::ELEMENT)
  40. {
  41. switch ($xmlReader->name) {
  42. case 'QueueURL':
  43. $xmlReader->read();
  44. if ($xmlReader->nodeType == \XMLReader::TEXT)
  45. {
  46. $queueName = $this->getQueueNameFromQueueURL($xmlReader->value);
  47. $this->queueNames[] = $queueName;
  48. }
  49. break;
  50. case 'NextMarker':
  51. $xmlReader->read();
  52. if ($xmlReader->nodeType == \XMLReader::TEXT)
  53. {
  54. $this->nextMarker = $xmlReader->value;
  55. }
  56. break;
  57. }
  58. }
  59. }
  60. } catch (\Exception $e) {
  61. throw new MnsException($statusCode, $e->getMessage(), $e);
  62. } catch (\Throwable $t) {
  63. throw new MnsException($statusCode, $t->getMessage());
  64. }
  65. }
  66. private function getQueueNameFromQueueURL($queueURL)
  67. {
  68. $pieces = explode("/", $queueURL);
  69. if (count($pieces) == 5)
  70. {
  71. return $pieces[4];
  72. }
  73. return "";
  74. }
  75. public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
  76. {
  77. $this->succeed = FALSE;
  78. $xmlReader = $this->loadXmlContent($content);
  79. try {
  80. $result = XMLParser::parseNormalError($xmlReader);
  81. throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  82. } catch (\Exception $e) {
  83. if ($exception != NULL) {
  84. throw $exception;
  85. } elseif($e instanceof MnsException) {
  86. throw $e;
  87. } else {
  88. throw new MnsException($statusCode, $e->getMessage());
  89. }
  90. } catch (\Throwable $t) {
  91. throw new MnsException($statusCode, $t->getMessage());
  92. }
  93. }
  94. }
  95. ?>