PageRenderTime 2938ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/backwpup/sdk/WindowsAzure/Queue/QueueRestProxy.php

https://bitbucket.org/cesarmedrano/cesarmedrano
PHP | 778 lines | 528 code | 85 blank | 165 comment | 14 complexity | 5ddfdcbd904eb270e56a6cece50d349a MD5 | raw file
  1. <?php
  2. /**
  3. * LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. *
  14. * PHP version 5
  15. *
  16. * @category Microsoft
  17. * @package WindowsAzure\Queue
  18. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  19. * @copyright 2012 Microsoft Corporation
  20. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  21. * @link https://github.com/windowsazure/azure-sdk-for-php
  22. */
  23. namespace WindowsAzure\Queue;
  24. use WindowsAzure\Common\Internal\Resources;
  25. use WindowsAzure\Common\Internal\Validate;
  26. use WindowsAzure\Common\Internal\Utilities;
  27. use WindowsAzure\Common\Internal\Http\IHttpClient;
  28. use WindowsAzure\Common\Internal\Http\Url;
  29. use WindowsAzure\Common\Internal\ServiceRestProxy;
  30. use WindowsAzure\Common\Models\GetServicePropertiesResult;
  31. use WindowsAzure\Common\Models\ServiceProperties;
  32. use WindowsAzure\Queue\Internal\IQueue;
  33. use WindowsAzure\Queue\Models\ListQueuesOptions;
  34. use WindowsAzure\Queue\Models\ListQueuesResult;
  35. use WindowsAzure\Queue\Models\CreateQueueOptions;
  36. use WindowsAzure\Queue\Models\QueueServiceOptions;
  37. use WindowsAzure\Queue\Models\GetQueueMetadataResult;
  38. use WindowsAzure\Queue\Models\CreateMessageOptions;
  39. use WindowsAzure\Queue\Models\QueueMessage;
  40. use WindowsAzure\Queue\Models\ListMessagesOptions;
  41. use WindowsAzure\Queue\Models\ListMessagesResult;
  42. use WindowsAzure\Queue\Models\PeekMessagesOptions;
  43. use WindowsAzure\Queue\Models\PeekMessagesResult;
  44. use WindowsAzure\Queue\Models\UpdateMessageResult;
  45. /**
  46. * This class constructs HTTP requests and receive HTTP responses for queue
  47. * service layer.
  48. *
  49. * @category Microsoft
  50. * @package WindowsAzure\Queue
  51. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  52. * @copyright 2012 Microsoft Corporation
  53. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  54. * @version Release: @package_version@
  55. * @link https://github.com/windowsazure/azure-sdk-for-php
  56. */
  57. class QueueRestProxy extends ServiceRestProxy implements IQueue
  58. {
  59. /**
  60. * Lists all queues in the storage account.
  61. *
  62. * @param ListQueuesOptions $options The optional list queue options.
  63. *
  64. * @return WindowsAzure\Queue\Models\ListQueuesResult
  65. */
  66. public function listQueues($options = null)
  67. {
  68. $method = Resources::HTTP_GET;
  69. $headers = array();
  70. $postParams = array();
  71. $queryParams = array();
  72. $path = Resources::EMPTY_STRING;
  73. $statusCode = Resources::STATUS_OK;
  74. if (is_null($options)) {
  75. $options = new ListQueuesOptions();
  76. }
  77. $timeout = $options->getTimeout();
  78. $maxResults = $options->getMaxResults();
  79. $include = $options->getIncludeMetadata();
  80. $include = $include ? 'metadata' : null;
  81. $prefix = $options->getPrefix();
  82. $marker = $options->getMarker();
  83. $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $timeout);
  84. $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'list');
  85. $this->addOptionalQueryParam($queryParams, Resources::QP_PREFIX, $prefix);
  86. $this->addOptionalQueryParam($queryParams, Resources::QP_MARKER, $marker);
  87. $this->addOptionalQueryParam($queryParams, Resources::QP_INCLUDE, $include);
  88. $this->addOptionalQueryParam(
  89. $queryParams,
  90. Resources::QP_MAX_RESULTS,
  91. $maxResults
  92. );
  93. $response = $this->send(
  94. $method,
  95. $headers,
  96. $queryParams,
  97. $postParams,
  98. $path,
  99. $statusCode
  100. );
  101. $parsed = $this->dataSerializer->unserialize($response->getBody());
  102. return ListQueuesResult::create($parsed);
  103. }
  104. /**
  105. * Clears all messages from the queue.
  106. *
  107. * If a queue contains a large number of messages, Clear Messages may time out
  108. * before all messages have been deleted. In this case the Queue service will
  109. * return status code 500 (Internal Server Error), with the additional error
  110. * code OperationTimedOut. If the operation times out, the client should
  111. * continue to retry Clear Messages until it succeeds, to ensure that all
  112. * messages have been deleted.
  113. *
  114. * @param string $queueName The name of the queue.
  115. * @param QueueServiceOptions $options The optional parameters.
  116. *
  117. * @return none
  118. */
  119. public function clearMessages($queueName, $options = null)
  120. {
  121. Validate::isString($queueName, 'queueName');
  122. Validate::notNullOrEmpty($queueName, 'queueName');
  123. $method = Resources::HTTP_DELETE;
  124. $headers = array();
  125. $postParams = array();
  126. $queryParams = array();
  127. $path = $queueName . '/messages';
  128. $body = Resources::EMPTY_STRING;
  129. $statusCode = Resources::STATUS_NO_CONTENT;
  130. if (is_null($options)) {
  131. $options = new QueueServiceOptions();
  132. }
  133. $this->addOptionalQueryParam(
  134. $queryParams,
  135. Resources::QP_TIMEOUT,
  136. $options->getTimeout()
  137. );
  138. $this->send(
  139. $method,
  140. $headers,
  141. $queryParams,
  142. $postParams,
  143. $path,
  144. $statusCode,
  145. $body
  146. );
  147. }
  148. /**
  149. * Adds a message to the queue and optionally sets a visibility timeout
  150. * for the message.
  151. *
  152. * @param string $queueName The name of the queue.
  153. * @param string $messageText The message contents.
  154. * @param CreateMessageOptions $options The optional parameters.
  155. *
  156. * @return none
  157. */
  158. public function createMessage($queueName, $messageText,
  159. $options = null
  160. ) {
  161. Validate::isString($queueName, 'queueName');
  162. Validate::notNullOrEmpty($queueName, 'queueName');
  163. Validate::isString($messageText, 'messageText');
  164. $method = Resources::HTTP_POST;
  165. $headers = array();
  166. $postParams = array();
  167. $queryParams = array();
  168. $path = $queueName . '/messages';
  169. $body = Resources::EMPTY_STRING;
  170. $statusCode = Resources::STATUS_CREATED;
  171. $message = new QueueMessage();
  172. $message->setMessageText($messageText);
  173. $body = $message->toXml($this->dataSerializer);
  174. if (is_null($options)) {
  175. $options = new CreateMessageOptions();
  176. }
  177. $this->addOptionalHeader(
  178. $headers,
  179. Resources::CONTENT_TYPE,
  180. Resources::URL_ENCODED_CONTENT_TYPE
  181. );
  182. $visibility = $options->getVisibilityTimeoutInSeconds();
  183. $timeToLive = $options->getTimeToLiveInSeconds();
  184. $timeout = $options->getTimeout();
  185. $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $timeout);
  186. $this->addOptionalQueryParam(
  187. $queryParams,
  188. Resources::QP_VISIBILITY_TIMEOUT,
  189. $visibility
  190. );
  191. $this->addOptionalQueryParam(
  192. $queryParams,
  193. Resources::QP_MESSAGE_TTL,
  194. $timeToLive
  195. );
  196. $this->send(
  197. $method,
  198. $headers,
  199. $queryParams,
  200. $postParams,
  201. $path,
  202. $statusCode,
  203. $body
  204. );
  205. }
  206. /**
  207. * Creates a new queue under the storage account.
  208. *
  209. * @param string $queueName The queue name.
  210. * @param QueueCreateOptions $options The Optional parameters.
  211. *
  212. * @return none
  213. */
  214. public function createQueue($queueName, $options = null)
  215. {
  216. Validate::isString($queueName, 'queueName');
  217. Validate::notNullOrEmpty($queueName, 'queueName');
  218. $method = Resources::HTTP_PUT;
  219. $headers = array();
  220. $postParams = array();
  221. $queryParams = array();
  222. $path = $queueName;
  223. $statusCode = array(
  224. Resources::STATUS_CREATED,
  225. Resources::STATUS_NO_CONTENT
  226. );
  227. if (is_null($options)) {
  228. $options = new CreateQueueOptions();
  229. }
  230. $metadata = $options->getMetadata();
  231. $timeout = $options->getTimeout();
  232. $headers = $this->generateMetadataHeaders($metadata);
  233. $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $timeout);
  234. $this->send(
  235. $method,
  236. $headers,
  237. $queryParams,
  238. $postParams,
  239. $path,
  240. $statusCode
  241. );
  242. }
  243. /**
  244. * Deletes a specified message from the queue.
  245. *
  246. * @param string $queueName The name of the queue.
  247. * @param string $messageId The id of the message.
  248. * @param string $popReceipt The valid pop receipt value returned
  249. * from an earlier call to the Get Messages or Update Message operation.
  250. * @param QueueServiceOptions $options The optional parameters.
  251. *
  252. * @return none
  253. */
  254. public function deleteMessage($queueName, $messageId, $popReceipt,
  255. $options = null
  256. ) {
  257. Validate::isString($queueName, 'queueName');
  258. Validate::notNullOrEmpty($queueName, 'queueName');
  259. Validate::isString($messageId, 'messageId');
  260. Validate::notNullOrEmpty($messageId, 'messageId');
  261. Validate::isString($popReceipt, 'popReceipt');
  262. Validate::notNullOrEmpty($popReceipt, 'popReceipt');
  263. $method = Resources::HTTP_DELETE;
  264. $headers = array();
  265. $postParams = array();
  266. $queryParams = array();
  267. $path = $queueName . '/messages/' . $messageId;
  268. $body = Resources::EMPTY_STRING;
  269. $statusCode = Resources::STATUS_NO_CONTENT;
  270. if (is_null($options)) {
  271. $options = new QueueServiceOptions();
  272. }
  273. $this->addOptionalQueryParam(
  274. $queryParams,
  275. Resources::QP_TIMEOUT,
  276. $options->getTimeout()
  277. );
  278. $this->addOptionalQueryParam(
  279. $queryParams,
  280. Resources::QP_POPRECEIPT,
  281. $popReceipt
  282. );
  283. $this->send(
  284. $method,
  285. $headers,
  286. $queryParams,
  287. $postParams,
  288. $path,
  289. $statusCode,
  290. $body
  291. );
  292. }
  293. /**
  294. * Deletes a queue.
  295. *
  296. * @param string $queueName The queue name.
  297. * @param QueueServiceOptions $options The optional parameters.
  298. *
  299. * @return none
  300. */
  301. public function deleteQueue($queueName, $options = null)
  302. {
  303. Validate::isString($queueName, 'queueName');
  304. Validate::notNullOrEmpty($queueName, 'queueName');
  305. $method = Resources::HTTP_DELETE;
  306. $headers = array();
  307. $postParams = array();
  308. $queryParams = array();
  309. $path = $queueName;
  310. $statusCode = Resources::STATUS_NO_CONTENT;
  311. if (is_null($options)) {
  312. $options = new QueueServiceOptions();
  313. }
  314. $this->addOptionalQueryParam(
  315. $queryParams,
  316. Resources::QP_TIMEOUT,
  317. $options->getTimeout()
  318. );
  319. $this->send(
  320. $method,
  321. $headers,
  322. $queryParams,
  323. $postParams,
  324. $path,
  325. $statusCode
  326. );
  327. }
  328. /**
  329. * Returns queue properties, including user-defined metadata.
  330. *
  331. * @param string $queueName The queue name.
  332. * @param QueueServiceOptions $options The optional parameters.
  333. *
  334. * @return WindowsAzure\Common\Models\GetQueueMetadataResult
  335. */
  336. public function getQueueMetadata($queueName, $options = null)
  337. {
  338. Validate::isString($queueName, 'queueName');
  339. Validate::notNullOrEmpty($queueName, 'queueName');
  340. $method = Resources::HTTP_GET;
  341. $headers = array();
  342. $postParams = array();
  343. $queryParams = array();
  344. $path = $queueName;
  345. $body = Resources::EMPTY_STRING;
  346. $statusCode = Resources::STATUS_OK;
  347. if (is_null($options)) {
  348. $options = new QueueServiceOptions();
  349. }
  350. $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'metadata');
  351. $this->addOptionalQueryParam(
  352. $queryParams,
  353. Resources::QP_TIMEOUT,
  354. $options->getTimeout()
  355. );
  356. $response = $this->send(
  357. $method,
  358. $headers,
  359. $queryParams,
  360. $postParams,
  361. $path,
  362. $statusCode,
  363. $body
  364. );
  365. $metadata = $this->getMetadataArray($response->getHeader());
  366. $maxCount = intval(
  367. $response->getHeader(Resources::X_MS_APPROXIMATE_MESSAGES_COUNT)
  368. );
  369. return new GetQueueMetadataResult($maxCount, $metadata);
  370. }
  371. /**
  372. * Gets the properties of the Queue service.
  373. *
  374. * @param QueueServiceOptions $options The optional parameters.
  375. *
  376. * @return WindowsAzure\Common\Models\GetServicePropertiesResult
  377. */
  378. public function getServiceProperties($options = null)
  379. {
  380. $method = Resources::HTTP_GET;
  381. $headers = array();
  382. $postParams = array();
  383. $queryParams = array();
  384. $path = Resources::EMPTY_STRING;
  385. $statusCode = Resources::STATUS_OK;
  386. if (is_null($options)) {
  387. $options = new QueueServiceOptions();
  388. }
  389. $this->addOptionalQueryParam(
  390. $queryParams,
  391. Resources::QP_TIMEOUT,
  392. $options->getTimeout()
  393. );
  394. $this->addOptionalQueryParam(
  395. $queryParams,
  396. Resources::QP_REST_TYPE,
  397. 'service'
  398. );
  399. $this->addOptionalQueryParam(
  400. $queryParams,
  401. Resources::QP_COMP,
  402. 'properties'
  403. );
  404. $response = $this->send(
  405. $method,
  406. $headers,
  407. $queryParams,
  408. $postParams,
  409. $path,
  410. $statusCode
  411. );
  412. $parsed = $this->dataSerializer->unserialize($response->getBody());
  413. return GetServicePropertiesResult::create($parsed);
  414. }
  415. /**
  416. * Lists all messages in the queue.
  417. *
  418. * @param string $queueName The queue name.
  419. * @param ListMessagesOptions $options The optional parameters.
  420. *
  421. * @return WindowsAzure\Common\Models\ListMessagesResult
  422. */
  423. public function listMessages($queueName, $options = null)
  424. {
  425. Validate::isString($queueName, 'queueName');
  426. Validate::notNullOrEmpty($queueName, 'queueName');
  427. $method = Resources::HTTP_GET;
  428. $headers = array();
  429. $queryParams = array();
  430. $postParams = array();
  431. $path = $queueName . '/messages';
  432. $statusCode = Resources::STATUS_OK;
  433. if (is_null($options)) {
  434. $options = new ListMessagesOptions();
  435. }
  436. $messagesCount = $options->getNumberOfMessages();
  437. $visibility = $options->getVisibilityTimeoutInSeconds();
  438. $timeout = $options->getTimeout();
  439. $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $timeout);
  440. $this->addOptionalQueryParam(
  441. $queryParams,
  442. Resources::QP_NUM_OF_MESSAGES,
  443. $messagesCount
  444. );
  445. $this->addOptionalQueryParam(
  446. $queryParams,
  447. Resources::QP_VISIBILITY_TIMEOUT,
  448. $visibility
  449. );
  450. $response = $this->send(
  451. $method,
  452. $headers,
  453. $queryParams,
  454. $postParams,
  455. $path,
  456. $statusCode
  457. );
  458. $parsed = $this->dataSerializer->unserialize($response->getBody());
  459. return ListMessagesResult::create($parsed);
  460. }
  461. /**
  462. * Retrieves a message from the front of the queue, without changing
  463. * the message visibility.
  464. *
  465. * @param string $queueName The queue name.
  466. * @param PeekMessagesOptions $options The optional parameters.
  467. *
  468. * @return WindowsAzure\Common\Models\PeekMessagesResult
  469. */
  470. public function peekMessages($queueName, $options = null)
  471. {
  472. Validate::isString($queueName, 'queueName');
  473. Validate::notNullOrEmpty($queueName, 'queueName');
  474. $method = Resources::HTTP_GET;
  475. $headers = array();
  476. $queryParams = array();
  477. $postParams = array();
  478. $path = $queueName . '/messages';
  479. $statusCode = Resources::STATUS_OK;
  480. if (is_null($options)) {
  481. $options = new PeekMessagesOptions();
  482. }
  483. $messagesCount = $options->getNumberOfMessages();
  484. $timeout = $options->getTimeout();
  485. $this->addOptionalQueryParam($queryParams, Resources::QP_PEEK_ONLY, 'true');
  486. $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $timeout);
  487. $this->addOptionalQueryParam(
  488. $queryParams,
  489. Resources::QP_NUM_OF_MESSAGES,
  490. $messagesCount
  491. );
  492. $response = $this->send(
  493. $method,
  494. $headers,
  495. $queryParams,
  496. $postParams,
  497. $path,
  498. $statusCode
  499. );
  500. $parsed = $this->dataSerializer->unserialize($response->getBody());
  501. return PeekMessagesResult::create($parsed);
  502. }
  503. /**
  504. * Sets user-defined metadata on the queue. To delete queue metadata, call
  505. * this API without specifying any metadata in $metadata.
  506. *
  507. * @param string $queueName The queue name.
  508. * @param array $metadata The metadata array.
  509. * @param QueueServiceOptions $options The optional parameters.
  510. *
  511. * @return none
  512. */
  513. public function setQueueMetadata($queueName, $metadata, $options = null)
  514. {
  515. Validate::isString($queueName, 'queueName');
  516. Validate::notNullOrEmpty($queueName, 'queueName');
  517. $this->validateMetadata($metadata);
  518. $method = Resources::HTTP_PUT;
  519. $headers = array();
  520. $queryParams = array();
  521. $postParams = array();
  522. $path = $queueName;
  523. $statusCode = Resources::STATUS_NO_CONTENT;
  524. $body = Resources::EMPTY_STRING;
  525. if (is_null($options)) {
  526. $options = new QueueServiceOptions();
  527. }
  528. $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'metadata');
  529. $this->addOptionalQueryParam(
  530. $queryParams,
  531. Resources::QP_TIMEOUT,
  532. $options->getTimeout()
  533. );
  534. $metadataHeaders = $this->generateMetadataHeaders($metadata);
  535. $headers = $metadataHeaders;
  536. $this->send(
  537. $method,
  538. $headers,
  539. $queryParams,
  540. $postParams,
  541. $path,
  542. $statusCode,
  543. $body
  544. );
  545. }
  546. /**
  547. * Sets the properties of the Queue service.
  548. *
  549. * It's recommended to use getServiceProperties, alter the returned object and
  550. * then use setServiceProperties with this altered object.
  551. *
  552. * @param array $serviceProperties The new service properties.
  553. * @param QueueServiceOptions $options The optional parameters.
  554. *
  555. * @return none
  556. */
  557. public function setServiceProperties($serviceProperties, $options = null)
  558. {
  559. Validate::isTrue(
  560. $serviceProperties instanceof ServiceProperties,
  561. Resources::INVALID_SVC_PROP_MSG
  562. );
  563. $method = Resources::HTTP_PUT;
  564. $headers = array();
  565. $postParams = array();
  566. $queryParams = array();
  567. $statusCode = Resources::STATUS_ACCEPTED;
  568. $path = Resources::EMPTY_STRING;
  569. $body = $serviceProperties->toXml($this->dataSerializer);
  570. if (is_null($options)) {
  571. $options = new QueueServiceOptions();
  572. }
  573. $this->addOptionalQueryParam(
  574. $queryParams,
  575. Resources::QP_REST_TYPE,
  576. 'service'
  577. );
  578. $this->addOptionalQueryParam(
  579. $queryParams,
  580. Resources::QP_COMP,
  581. 'properties'
  582. );
  583. $this->addOptionalQueryParam(
  584. $queryParams,
  585. Resources::QP_TIMEOUT,
  586. $options->getTimeout()
  587. );
  588. $this->addOptionalHeader(
  589. $headers,
  590. Resources::CONTENT_TYPE,
  591. Resources::URL_ENCODED_CONTENT_TYPE
  592. );
  593. $this->send(
  594. $method,
  595. $headers,
  596. $queryParams,
  597. $postParams,
  598. $path,
  599. $statusCode,
  600. $body
  601. );
  602. }
  603. /**
  604. * Updates the visibility timeout of a message and/or the message contents.
  605. *
  606. * @param string $queueName The queue name.
  607. * @param string $messageId The id of the message.
  608. * @param string $popReceipt The valid pop receipt
  609. * value returned from an earlier call to the Get Messages or Update Message
  610. * operation.
  611. * @param string $messageText The message contents.
  612. * @param int $visibilityTimeoutInSeconds Specifies the new
  613. * visibility timeout value, in seconds, relative to server time.
  614. * The new value must be larger than or equal to 0, and cannot be larger
  615. * than 7 days. The visibility timeout of a message cannot be set to a value
  616. * later than the expiry time. A message can be updated until it has been
  617. * deleted or has expired.
  618. * @param QueueServiceOptions $options The optional
  619. * parameters.
  620. *
  621. * @return WindowsAzure\Common\Models\UpdateMessageResult
  622. */
  623. public function updateMessage($queueName, $messageId, $popReceipt, $messageText,
  624. $visibilityTimeoutInSeconds, $options = null
  625. ) {
  626. Validate::isString($queueName, 'queueName');
  627. Validate::notNullOrEmpty($queueName, 'queueName');
  628. Validate::isString($messageId, 'messageId');
  629. Validate::notNullOrEmpty($messageId, 'messageId');
  630. Validate::isString($popReceipt, 'popReceipt');
  631. Validate::notNullOrEmpty($popReceipt, 'popReceipt');
  632. Validate::isString($messageText, 'messageText');
  633. Validate::isInteger(
  634. $visibilityTimeoutInSeconds,
  635. 'visibilityTimeoutInSeconds'
  636. );
  637. Validate::notNull(
  638. $visibilityTimeoutInSeconds,
  639. 'visibilityTimeoutInSeconds'
  640. );
  641. $method = Resources::HTTP_PUT;
  642. $headers = array();
  643. $postParams = array();
  644. $queryParams = array();
  645. $path = $queueName . '/messages' . '/' . $messageId;
  646. $body = Resources::EMPTY_STRING;
  647. $statusCode = Resources::STATUS_NO_CONTENT;
  648. if (is_null($options)) {
  649. $options = new QueueServiceOptions();
  650. }
  651. $this->addOptionalQueryParam(
  652. $queryParams,
  653. Resources::QP_VISIBILITY_TIMEOUT,
  654. $visibilityTimeoutInSeconds
  655. );
  656. $this->addOptionalQueryParam(
  657. $queryParams,
  658. Resources::QP_TIMEOUT,
  659. $options->getTimeout()
  660. );
  661. $this->addOptionalQueryParam(
  662. $queryParams,
  663. Resources::QP_POPRECEIPT,
  664. $popReceipt
  665. );
  666. if (!empty($messageText)) {
  667. $this->addOptionalHeader(
  668. $headers,
  669. Resources::CONTENT_TYPE,
  670. Resources::URL_ENCODED_CONTENT_TYPE
  671. );
  672. $message = new QueueMessage();
  673. $message->setMessageText($messageText);
  674. $body = $message->toXml($this->dataSerializer);
  675. }
  676. $response = $this->send(
  677. $method,
  678. $headers,
  679. $queryParams,
  680. $postParams,
  681. $path,
  682. $statusCode,
  683. $body
  684. );
  685. $popReceipt = $response->getHeader(Resources::X_MS_POPRECEIPT);
  686. $timeNextVisible = $response->getHeader(Resources::X_MS_TIME_NEXT_VISIBLE);
  687. $date = Utilities::rfc1123ToDateTime($timeNextVisible);
  688. $result = new UpdateMessageResult();
  689. $result->setPopReceipt($popReceipt);
  690. $result->setTimeNextVisible($date);
  691. return $result;
  692. }
  693. }