No Description

GetTopicAttributeResponse.php 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace AliyunMNS\Responses;
  3. use AliyunMNS\Constants;
  4. use AliyunMNS\Model\TopicAttributes;
  5. use AliyunMNS\Exception\MnsException;
  6. use AliyunMNS\Exception\TopicNotExistException;
  7. use AliyunMNS\Responses\BaseResponse;
  8. use AliyunMNS\Common\XMLParser;
  9. class GetTopicAttributeResponse extends BaseResponse
  10. {
  11. private $attributes;
  12. public function __construct()
  13. {
  14. $this->attributes = NULL;
  15. }
  16. public function getTopicAttributes()
  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. $this->attributes = TopicAttributes::fromXML($xmlReader);
  34. }
  35. catch (\Exception $e)
  36. {
  37. throw new MnsException($statusCode, $e->getMessage(), $e);
  38. }
  39. catch (\Throwable $t)
  40. {
  41. throw new MnsException($statusCode, $t->getMessage());
  42. }
  43. }
  44. public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
  45. {
  46. $this->succeed = FALSE;
  47. $xmlReader = $this->loadXmlContent($content);
  48. try
  49. {
  50. $result = XMLParser::parseNormalError($xmlReader);
  51. if ($result['Code'] == Constants::TOPIC_NOT_EXIST)
  52. {
  53. throw new TopicNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  54. }
  55. throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
  56. }
  57. catch (\Exception $e)
  58. {
  59. if ($exception != NULL)
  60. {
  61. throw $exception;
  62. }
  63. elseif ($e instanceof MnsException)
  64. {
  65. throw $e;
  66. }
  67. else
  68. {
  69. throw new MnsException($statusCode, $e->getMessage());
  70. }
  71. }
  72. catch (\Throwable $t)
  73. {
  74. throw new MnsException($statusCode, $t->getMessage());
  75. }
  76. }
  77. }
  78. ?>