No Description

ListSubscriptionResponse.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace AliyunMNS\Responses;
  3. use AliyunMNS\Exception\MnsException;
  4. use AliyunMNS\Responses\BaseResponse;
  5. use AliyunMNS\Common\XMLParser;
  6. class ListSubscriptionResponse extends BaseResponse
  7. {
  8. private $SubscriptionNames;
  9. private $nextMarker;
  10. public function __construct()
  11. {
  12. $this->SubscriptionNames = array();
  13. $this->nextMarker = NULL;
  14. }
  15. public function isFinished()
  16. {
  17. return $this->nextMarker == NULL;
  18. }
  19. public function getSubscriptionNames()
  20. {
  21. return $this->SubscriptionNames;
  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 'SubscriptionURL':
  43. $xmlReader->read();
  44. if ($xmlReader->nodeType == \XMLReader::TEXT)
  45. {
  46. $subscriptionName = $this->getSubscriptionNameFromSubscriptionURL($xmlReader->value);
  47. $this->SubscriptionNames[] = $subscriptionName;
  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. }
  61. catch (\Exception $e)
  62. {
  63. throw new MnsException($statusCode, $e->getMessage(), $e);
  64. }
  65. catch (\Throwable $t)
  66. {
  67. throw new MnsException($statusCode, $t->getMessage());
  68. }
  69. }
  70. private function getSubscriptionNameFromSubscriptionURL($subscriptionURL)
  71. {
  72. $pieces = explode("/", $subscriptionURL);
  73. if (count($pieces) == 7)
  74. {
  75. return $pieces[6];
  76. }
  77. return "";
  78. }
  79. public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
  80. {
  81. $this->succeed = FALSE;
  82. $xmlReader = $this->loadXmlContent($content);
  83. try
  84. {
  85. $result = XMLParser::parseNormalError($xmlReader);
  86. throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  87. }
  88. catch (\Exception $e)
  89. {
  90. if ($exception != NULL)
  91. {
  92. throw $exception;
  93. }
  94. elseif ($e instanceof MnsException)
  95. {
  96. throw $e;
  97. }
  98. else
  99. {
  100. throw new MnsException($statusCode, $e->getMessage());
  101. }
  102. }
  103. catch (\Throwable $t)
  104. {
  105. throw new MnsException($statusCode, $t->getMessage());
  106. }
  107. }
  108. }