123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace AliyunMNS\Responses;
- use AliyunMNS\Exception\MnsException;
- use AliyunMNS\Responses\BaseResponse;
- use AliyunMNS\Common\XMLParser;
- class ListSubscriptionResponse extends BaseResponse
- {
- private $SubscriptionNames;
- private $nextMarker;
- public function __construct()
- {
- $this->SubscriptionNames = array();
- $this->nextMarker = NULL;
- }
- public function isFinished()
- {
- return $this->nextMarker == NULL;
- }
- public function getSubscriptionNames()
- {
- return $this->SubscriptionNames;
- }
- public function getNextMarker()
- {
- return $this->nextMarker;
- }
- public function parseResponse($statusCode, $content)
- {
- $this->statusCode = $statusCode;
- if ($statusCode != 200) {
- $this->parseErrorResponse($statusCode, $content);
- return;
- }
- $this->succeed = TRUE;
- $xmlReader = $this->loadXmlContent($content);
- try {
- while ($xmlReader->read())
- {
- if ($xmlReader->nodeType == \XMLReader::ELEMENT)
- {
- switch ($xmlReader->name) {
- case 'SubscriptionURL':
- $xmlReader->read();
- if ($xmlReader->nodeType == \XMLReader::TEXT)
- {
- $subscriptionName = $this->getSubscriptionNameFromSubscriptionURL($xmlReader->value);
- $this->SubscriptionNames[] = $subscriptionName;
- }
- break;
- case 'NextMarker':
- $xmlReader->read();
- if ($xmlReader->nodeType == \XMLReader::TEXT)
- {
- $this->nextMarker = $xmlReader->value;
- }
- break;
- }
- }
- }
- }
- catch (\Exception $e)
- {
- throw new MnsException($statusCode, $e->getMessage(), $e);
- }
- catch (\Throwable $t)
- {
- throw new MnsException($statusCode, $t->getMessage());
- }
- }
- private function getSubscriptionNameFromSubscriptionURL($subscriptionURL)
- {
- $pieces = explode("/", $subscriptionURL);
- if (count($pieces) == 7)
- {
- return $pieces[6];
- }
- return "";
- }
- public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
- {
- $this->succeed = FALSE;
- $xmlReader = $this->loadXmlContent($content);
- try
- {
- $result = XMLParser::parseNormalError($xmlReader);
- throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
- }
- catch (\Exception $e)
- {
- if ($exception != NULL)
- {
- throw $exception;
- }
- elseif ($e instanceof MnsException)
- {
- throw $e;
- }
- else
- {
- throw new MnsException($statusCode, $e->getMessage());
- }
- }
- catch (\Throwable $t)
- {
- throw new MnsException($statusCode, $t->getMessage());
- }
- }
- }
|