No Description

GetSubscriptionAttributeResponse.php 2.3KB

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