1
|
|
|
<?php |
2
|
|
|
namespace AliyunMNS\Responses; |
3
|
|
|
|
4
|
|
|
use AliyunMNS\Constants; |
5
|
|
|
use AliyunMNS\Model\SubscriptionAttributes; |
6
|
|
|
use AliyunMNS\Exception\MnsException; |
7
|
|
|
use AliyunMNS\Exception\SubscriptionNotExistException; |
8
|
|
|
use AliyunMNS\Responses\BaseResponse; |
9
|
|
|
use AliyunMNS\Common\XMLParser; |
10
|
|
|
|
11
|
|
|
class GetSubscriptionAttributeResponse extends BaseResponse |
12
|
|
|
{ |
13
|
|
|
private $attributes; |
14
|
|
|
|
15
|
|
|
public function __construct() |
16
|
|
|
{ |
17
|
|
|
$this->attributes = NULL; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function getSubscriptionAttributes() |
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
|
|
|
{ |
41
|
|
|
$this->attributes = SubscriptionAttributes::fromXML($xmlReader); |
42
|
|
|
} |
43
|
|
|
catch (\Exception $e) |
44
|
|
|
{ |
45
|
|
|
throw new MnsException($statusCode, $e->getMessage(), $e); |
46
|
|
|
} |
47
|
|
|
catch (\Throwable $t) |
48
|
|
|
{ |
49
|
|
|
throw new MnsException($statusCode, $t->getMessage()); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL) |
54
|
|
|
{ |
55
|
|
|
$this->succeed = FALSE; |
56
|
|
|
$xmlReader = $this->loadXmlContent($content); |
57
|
|
|
|
58
|
|
|
try |
59
|
|
|
{ |
60
|
|
|
$result = XMLParser::parseNormalError($xmlReader); |
61
|
|
|
if ($result['Code'] == Constants::SUBSCRIPTION_NOT_EXIST) |
62
|
|
|
{ |
63
|
|
|
throw new SubscriptionNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']); |
64
|
|
|
} |
65
|
|
|
throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']); |
66
|
|
|
} |
67
|
|
|
catch (\Exception $e) |
68
|
|
|
{ |
69
|
|
|
if ($exception != NULL) |
70
|
|
|
{ |
71
|
|
|
throw $exception; |
72
|
|
|
} |
73
|
|
|
elseif ($e instanceof MnsException) |
74
|
|
|
{ |
75
|
|
|
throw $e; |
76
|
|
|
} |
77
|
|
|
else |
78
|
|
|
{ |
79
|
|
|
throw new MnsException($statusCode, $e->getMessage()); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
catch (\Throwable $t) |
83
|
|
|
{ |
84
|
|
|
throw new MnsException($statusCode, $t->getMessage()); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
?> |
89
|
|
|
|