No Description

CreateTopicResponse.php 2.1KB

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