|
1
|
|
|
<?php |
|
2
|
|
|
namespace AliyunMNS\Responses; |
|
3
|
|
|
|
|
4
|
|
|
use AliyunMNS\Exception\MnsException; |
|
5
|
|
|
use AliyunMNS\Responses\BaseResponse; |
|
6
|
|
|
use AliyunMNS\Common\XMLParser; |
|
7
|
|
|
|
|
8
|
|
|
class ListQueueResponse extends BaseResponse |
|
9
|
|
|
{ |
|
10
|
|
|
private $queueNames; |
|
11
|
|
|
private $nextMarker; |
|
12
|
|
|
|
|
13
|
|
|
public function __construct() |
|
14
|
|
|
{ |
|
15
|
|
|
$this->queueNames = array(); |
|
16
|
|
|
$this->nextMarker = NULL; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function isFinished() |
|
20
|
|
|
{ |
|
21
|
|
|
return $this->nextMarker == NULL; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function getQueueNames() |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->queueNames; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function getNextMarker() |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->nextMarker; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function parseResponse($statusCode, $content) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->statusCode = $statusCode; |
|
37
|
|
|
if ($statusCode != 200) { |
|
38
|
|
|
$this->parseErrorResponse($statusCode, $content); |
|
39
|
|
|
return; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$this->succeed = TRUE; |
|
43
|
|
|
$xmlReader = $this->loadXmlContent($content); |
|
44
|
|
|
|
|
45
|
|
|
try { |
|
46
|
|
|
while ($xmlReader->read()) |
|
47
|
|
|
{ |
|
48
|
|
|
if ($xmlReader->nodeType == \XMLReader::ELEMENT) |
|
49
|
|
|
{ |
|
50
|
|
|
switch ($xmlReader->name) { |
|
51
|
|
|
case 'QueueURL': |
|
52
|
|
|
$xmlReader->read(); |
|
53
|
|
|
if ($xmlReader->nodeType == \XMLReader::TEXT) |
|
54
|
|
|
{ |
|
55
|
|
|
$queueName = $this->getQueueNameFromQueueURL($xmlReader->value); |
|
56
|
|
|
$this->queueNames[] = $queueName; |
|
57
|
|
|
} |
|
58
|
|
|
break; |
|
59
|
|
|
case 'NextMarker': |
|
60
|
|
|
$xmlReader->read(); |
|
61
|
|
|
if ($xmlReader->nodeType == \XMLReader::TEXT) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->nextMarker = $xmlReader->value; |
|
64
|
|
|
} |
|
65
|
|
|
break; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} catch (\Exception $e) { |
|
70
|
|
|
throw new MnsException($statusCode, $e->getMessage(), $e); |
|
71
|
|
|
} catch (\Throwable $t) { |
|
72
|
|
|
throw new MnsException($statusCode, $t->getMessage()); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
private function getQueueNameFromQueueURL($queueURL) |
|
77
|
|
|
{ |
|
78
|
|
|
$pieces = explode("/", $queueURL); |
|
79
|
|
|
if (count($pieces) == 5) |
|
80
|
|
|
{ |
|
81
|
|
|
return $pieces[4]; |
|
82
|
|
|
} |
|
83
|
|
|
return ""; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->succeed = FALSE; |
|
89
|
|
|
$xmlReader = $this->loadXmlContent($content); |
|
90
|
|
|
|
|
91
|
|
|
try { |
|
92
|
|
|
$result = XMLParser::parseNormalError($xmlReader); |
|
93
|
|
|
|
|
94
|
|
|
throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']); |
|
95
|
|
|
} catch (\Exception $e) { |
|
96
|
|
|
if ($exception != NULL) { |
|
97
|
|
|
throw $exception; |
|
98
|
|
|
} elseif($e instanceof MnsException) { |
|
99
|
|
|
throw $e; |
|
100
|
|
|
} else { |
|
101
|
|
|
throw new MnsException($statusCode, $e->getMessage()); |
|
102
|
|
|
} |
|
103
|
|
|
} catch (\Throwable $t) { |
|
104
|
|
|
throw new MnsException($statusCode, $t->getMessage()); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
?> |
|
110
|
|
|
|