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