This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathServiceBusRestProxy.php
907 lines (813 loc) · 30.2 KB
/
ServiceBusRestProxy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
<?php
/**
* LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PHP version 5
*
* @category Microsoft
*
* @author Azure PHP SDK <[email protected]>
* @copyright 2012 Microsoft Corporation
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
*
* @link https://github.com/WindowsAzure/azure-sdk-for-php
*/
namespace WindowsAzure\ServiceBus;
use Psr\Http\Message\ResponseInterface;
use WindowsAzure\Common\Internal\Http\IHttpClient;
use WindowsAzure\Common\Internal\Serialization\ISerializer;
use WindowsAzure\Common\Internal\ServiceRestProxy;
use WindowsAzure\Common\Internal\Http\HttpCallContext;
use WindowsAzure\Common\Internal\Http\HttpClient;
use WindowsAzure\Common\Internal\Serialization\XmlSerializer;
use WindowsAzure\Common\Internal\Atom\Content;
use WindowsAzure\Common\Internal\Atom\Entry;
use WindowsAzure\ServiceBus\Internal\IServiceBus;
use WindowsAzure\ServiceBus\Models\BrokeredMessage;
use WindowsAzure\ServiceBus\Models\BrokerProperties;
use WindowsAzure\ServiceBus\Models\ListQueuesOptions;
use WindowsAzure\ServiceBus\Models\ListQueuesResult;
use WindowsAzure\ServiceBus\Models\ListSubscriptionsOptions;
use WindowsAzure\ServiceBus\Models\ListSubscriptionsResult;
use WindowsAzure\ServiceBus\Models\ListTopicsOptions;
use WindowsAzure\ServiceBus\Models\ListTopicsResult;
use WindowsAzure\ServiceBus\Models\ListRulesOptions;
use WindowsAzure\ServiceBus\Models\ListRulesResult;
use WindowsAzure\ServiceBus\Models\ListOptions;
use WindowsAzure\ServiceBus\Models\QueueInfo;
use WindowsAzure\ServiceBus\Models\ReceiveMessageOptions;
use WindowsAzure\ServiceBus\Models\RuleInfo;
use WindowsAzure\ServiceBus\Models\SubscriptionInfo;
use WindowsAzure\ServiceBus\Models\TopicInfo;
use WindowsAzure\Common\Internal\Resources;
use WindowsAzure\Common\Internal\Validate;
/**
* This class constructs HTTP requests and receive HTTP responses
* for Service Bus.
*
* @category Microsoft
*
* @author Azure PHP SDK <[email protected]>
* @copyright 2012 Microsoft Corporation
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
*
* @version Release: 0.5.0_2016-11
*
* @link https://github.com/WindowsAzure/azure-sdk-for-php
*/
class ServiceBusRestProxy extends ServiceRestProxy implements IServiceBus
{
/**
* Creates a ServiceBusRestProxy with specified parameter.
*
* @param IHttpClient $channel The channel to communicate
* @param string $uri The URI of Service Bus service
* @param ISerializer $dataSerializer The serializer of the Service Bus
*/
public function __construct(IHttpClient $channel, $uri, ISerializer $dataSerializer)
{
parent::__construct(
$channel,
$uri,
Resources::EMPTY_STRING,
$dataSerializer
);
}
/**
* Sends a brokered message.
*
* Queues:
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780775
*
* Topic Subscriptions:
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780786
*
* @param string $path The path to send message
* @param BrokeredMessage $brokeredMessage The brokered message
*/
public function sendMessage($path, BrokeredMessage $brokeredMessage)
{
$httpCallContext = new HttpCallContext();
$httpCallContext->setMethod(Resources::HTTP_POST);
$httpCallContext->addStatusCode(Resources::STATUS_CREATED);
$httpCallContext->setPath($path);
$contentType = $brokeredMessage->getContentType();
if (!is_null($contentType)) {
$httpCallContext->addHeader(
Resources::CONTENT_TYPE,
$contentType
);
}
$brokerProperties = $brokeredMessage->getBrokerProperties();
if (!is_null($brokerProperties)) {
$httpCallContext->addHeader(
Resources::BROKER_PROPERTIES,
$brokerProperties->toString()
);
}
$customProperties = $brokeredMessage->getProperties();
if (!empty($customProperties)) {
foreach ($customProperties as $key => $value) {
$value = json_encode($value);
$httpCallContext->addHeader($key, $value);
}
}
$httpCallContext->setBody($brokeredMessage->getBody());
$this->sendHttpContext($httpCallContext);
}
/**
* Sends a queue message.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780775
*
* @param string $queueName The name of the queue
* @param BrokeredMessage $brokeredMessage The brokered message
*/
public function sendQueueMessage($queueName, BrokeredMessage $brokeredMessage)
{
$path = sprintf(Resources::SEND_MESSAGE_PATH, $queueName);
$this->sendMessage($path, $brokeredMessage);
}
/**
* Receives a queue message.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780735
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780756
*
* @param string $queueName The name of the
* queue
* @param ReceiveMessageOptions|null $receiveMessageOptions The options to
* receive the message
*
* @return BrokeredMessage
*/
public function receiveQueueMessage(
$queueName,
ReceiveMessageOptions $receiveMessageOptions = null
) {
$queueMessagePath = sprintf(Resources::RECEIVE_MESSAGE_PATH, $queueName);
return $this->receiveMessage(
$queueMessagePath,
$receiveMessageOptions
);
}
// @codingStandardsIgnoreStart
/**
* Receives a message.
*
* Queues:
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780735
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780756
*
* Topic Subscriptions:
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780722
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780770
*
* @param string $path The path of the
* message
* @param ReceiveMessageOptions $receiveMessageOptions The options to
* receive the message
*
* @return BrokeredMessage
*/
public function receiveMessage($path, ReceiveMessageOptions $receiveMessageOptions = null)
{
if (is_null($receiveMessageOptions)) {
$receiveMessageOptions = new ReceiveMessageOptions();
}
$httpCallContext = new HttpCallContext();
$httpCallContext->setPath($path);
$httpCallContext->addStatusCode(Resources::STATUS_CREATED);
$httpCallContext->addStatusCode(Resources::STATUS_NO_CONTENT);
$httpCallContext->addStatusCode(Resources::STATUS_OK);
$timeout = $receiveMessageOptions->getTimeout();
if (!is_null($timeout)) {
$httpCallContext->addQueryParameter('timeout', $timeout);
}
if ($receiveMessageOptions->getIsReceiveAndDelete()) {
$httpCallContext->setMethod(Resources::HTTP_DELETE);
} elseif ($receiveMessageOptions->getIsPeekLock()) {
$httpCallContext->setMethod(Resources::HTTP_POST);
} else {
throw new \InvalidArgumentException(
Resources::INVALID_RECEIVE_MODE_MSG
);
}
$response = $this->sendHttpContext($httpCallContext);
if ($response->getStatusCode() === Resources::STATUS_NO_CONTENT) {
$brokeredMessage = null;
} else {
$responseHeaders = HttpClient::getResponseHeaders($response);
$brokerProperties = new BrokerProperties();
if (array_key_exists('brokerproperties', $responseHeaders)) {
$brokerProperties = BrokerProperties::create($responseHeaders['brokerproperties']);
}
if (array_key_exists('location', $responseHeaders)) {
$brokerProperties->setLockLocation($responseHeaders['location']);
}
$brokeredMessage = new BrokeredMessage();
$brokeredMessage->setBrokerProperties($brokerProperties);
if (array_key_exists(Resources::CONTENT_TYPE, $responseHeaders)) {
$brokeredMessage->setContentType($responseHeaders[Resources::CONTENT_TYPE]);
}
if (array_key_exists('date', $responseHeaders)) {
$brokeredMessage->setDate($responseHeaders['date']);
}
$brokeredMessage->setBody($response->getBody());
foreach ($responseHeaders as $headerKey => $value) {
$decodedValue = json_decode($value);
if (is_scalar($decodedValue)) {
$brokeredMessage->setProperty(
$headerKey,
$decodedValue
);
}
}
}
return $brokeredMessage;
}
// @codingStandardsIgnoreEnd
/**
* Sends a brokered message to a specified topic.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780786
*
* @param string $topicName The name of the topic
* @param BrokeredMessage $brokeredMessage The brokered message
*/
public function sendTopicMessage($topicName, BrokeredMessage $brokeredMessage)
{
$topicMessagePath = sprintf(Resources::SEND_MESSAGE_PATH, $topicName);
$this->sendMessage($topicMessagePath, $brokeredMessage);
}
/**
* Receives a subscription message.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780722
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780770
*
* @param string $topicName The name of the
* topic
* @param string $subscriptionName The name of the
* subscription
* @param ReceiveMessageOptions|null $receiveMessageOptions The options to
* receive the subscription message
*
* @return BrokeredMessage
*/
public function receiveSubscriptionMessage(
$topicName,
$subscriptionName,
ReceiveMessageOptions $receiveMessageOptions = null
) {
$messagePath = sprintf(
Resources::RECEIVE_SUBSCRIPTION_MESSAGE_PATH,
$topicName,
$subscriptionName
);
$brokeredMessage = $this->receiveMessage(
$messagePath,
$receiveMessageOptions
);
return $brokeredMessage;
}
/**
* Unlocks a brokered message.
*
* Queues:
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780723
*
* Topic Subscriptions:
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780737
*
* @param BrokeredMessage $brokeredMessage The brokered message
*/
public function unlockMessage(BrokeredMessage $brokeredMessage)
{
$httpCallContext = new HttpCallContext();
$httpCallContext->setMethod(Resources::HTTP_PUT);
$lockLocation = $brokeredMessage->getLockLocation();
$lockLocationArray = parse_url($lockLocation);
$lockLocationPath = Resources::EMPTY_STRING;
if (array_key_exists(Resources::PHP_URL_PATH, $lockLocationArray)) {
$lockLocationPath = $lockLocationArray[Resources::PHP_URL_PATH];
$lockLocationPath = preg_replace(
'@^\/@',
Resources::EMPTY_STRING,
$lockLocationPath
);
}
$httpCallContext->setPath($lockLocationPath);
$httpCallContext->addStatusCode(Resources::STATUS_OK);
$this->sendHttpContext($httpCallContext);
}
/**
* Deletes a brokered message.
*
* Queues:
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780767
*
* Topic Subscriptions:
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780768
*
* @param BrokeredMessage $brokeredMessage The brokered message
*/
public function deleteMessage(BrokeredMessage $brokeredMessage)
{
$httpCallContext = new HttpCallContext();
$httpCallContext->setMethod(Resources::HTTP_DELETE);
$lockLocation = $brokeredMessage->getLockLocation();
$lockLocationArray = parse_url($lockLocation);
$lockLocationPath = Resources::EMPTY_STRING;
if (array_key_exists(Resources::PHP_URL_PATH, $lockLocationArray)) {
$lockLocationPath = $lockLocationArray[Resources::PHP_URL_PATH];
$lockLocationPath = preg_replace(
'@^\/@',
Resources::EMPTY_STRING,
$lockLocationPath
);
}
if (empty($lockLocationPath)) {
throw new \InvalidArgumentException(
Resources::MISSING_LOCK_LOCATION_MSG
);
}
$httpCallContext->setPath($lockLocationPath);
$httpCallContext->addStatusCode(Resources::STATUS_OK);
$this->sendHttpContext($httpCallContext);
}
/**
* Creates a queue with a specified queue information.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780716
*
* @param QueueInfo $queueInfo The information of the queue
*
* @return QueueInfo
*/
public function createQueue(QueueInfo $queueInfo)
{
$httpCallContext = new HttpCallContext();
$httpCallContext->setMethod(Resources::HTTP_PUT);
$httpCallContext->setPath($queueInfo->getTitle());
$httpCallContext->addHeader(
Resources::CONTENT_TYPE,
Resources::ATOM_ENTRY_CONTENT_TYPE
);
$httpCallContext->addStatusCode(Resources::STATUS_CREATED);
$xmlWriter = new \XMLWriter();
$xmlWriter->openMemory();
$queueInfo->writeXml($xmlWriter);
$body = $xmlWriter->outputMemory();
$httpCallContext->setBody($body);
$response = $this->sendHttpContext($httpCallContext);
$queueInfo = new QueueInfo();
$queueInfo->parseXml($response->getBody());
return $queueInfo;
}
/**
* Deletes a queue.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780747
*
* @param string $queuePath The path of the queue
*/
public function deleteQueue($queuePath)
{
Validate::isString($queuePath, 'queuePath');
Validate::notNullOrEmpty($queuePath, 'queuePath');
$httpCallContext = new HttpCallContext();
$httpCallContext->setMethod(Resources::HTTP_DELETE);
$httpCallContext->addStatusCode(Resources::STATUS_OK);
$httpCallContext->setPath($queuePath);
$this->sendHttpContext($httpCallContext);
}
/**
* Gets a queue with specified path.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780764
*
* @param string $queuePath The path of the queue
*
* @return QueueInfo
*/
public function getQueue($queuePath)
{
$httpCallContext = new HttpCallContext();
$httpCallContext->setPath($queuePath);
$httpCallContext->setMethod(Resources::HTTP_GET);
$httpCallContext->addStatusCode(Resources::STATUS_OK);
$response = $this->sendHttpContext($httpCallContext);
$queueInfo = new QueueInfo();
$queueInfo->parseXml($response->getBody());
return $queueInfo;
}
/**
* Lists a queue.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780759
*
* @param ListQueuesOptions|null $listQueuesOptions The options to list the
* queues
*
* @return ListQueuesResult
*/
public function listQueues(ListQueuesOptions $listQueuesOptions = null)
{
$response = $this->_listOptions(
$listQueuesOptions,
Resources::LIST_QUEUES_PATH
);
$listQueuesResult = new ListQueuesResult();
$listQueuesResult->parseXml($response->getBody());
return $listQueuesResult;
}
/**
* The base method of all the list operations.
*
* @param ListOptions $listOptions The options for list operation
* @param string $path The path of the list operation
*
* @return ResponseInterface
*/
private function _listOptions($listOptions, $path)
{
if (is_null($listOptions)) {
$listOptions = new ListOptions();
}
$httpCallContext = new HttpCallContext();
$httpCallContext->setMethod(Resources::HTTP_GET);
$httpCallContext->setPath($path);
$httpCallContext->addStatusCode(Resources::STATUS_OK);
$top = $listOptions->getTop();
$skip = $listOptions->getSkip();
if (!empty($top)) {
$httpCallContext->addQueryParameter(Resources::QP_TOP, $top);
}
if (!empty($skip)) {
$httpCallContext->addQueryParameter(Resources::QP_SKIP, $skip);
}
return $this->sendHttpContext($httpCallContext);
}
/**
* Creates a topic with specified topic info.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780728
*
* @param TopicInfo $topicInfo The information of the topic
*
* @return TopicInfo
*/
public function createTopic(TopicInfo $topicInfo)
{
Validate::notNullOrEmpty($topicInfo, 'topicInfo');
$httpCallContext = new HttpCallContext();
$httpCallContext->setMethod(Resources::HTTP_PUT);
$httpCallContext->setPath($topicInfo->getTitle());
$httpCallContext->addHeader(
Resources::CONTENT_TYPE,
Resources::ATOM_ENTRY_CONTENT_TYPE
);
$httpCallContext->addStatusCode(Resources::STATUS_CREATED);
$topicDescriptionXml = XmlSerializer::objectSerialize(
$topicInfo->getTopicDescription(),
'TopicDescription'
);
$entry = new Entry();
$content = new Content($topicDescriptionXml);
$content->setType(Resources::XML_CONTENT_TYPE);
$entry->setContent($content);
$entry->setAttribute(
Resources::XMLNS,
Resources::SERVICE_BUS_NAMESPACE
);
$xmlWriter = new \XMLWriter();
$xmlWriter->openMemory();
$entry->writeXml($xmlWriter);
$httpCallContext->setBody($xmlWriter->outputMemory());
$response = $this->sendHttpContext($httpCallContext);
$topicInfo = new TopicInfo();
$topicInfo->parseXml($response->getBody());
return $topicInfo;
}
/**
* Deletes a topic with specified topic path.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780721
*
* @param string $topicPath The path of the topic
*/
public function deleteTopic($topicPath)
{
$httpCallContext = new HttpCallContext();
$httpCallContext->setMethod(Resources::HTTP_DELETE);
$httpCallContext->setPath($topicPath);
$httpCallContext->addStatusCode(Resources::STATUS_OK);
$this->sendHttpContext($httpCallContext);
}
/**
* Gets a topic.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780769
*
* @param string $topicPath The path of the topic
*
* @return TopicInfo
*/
public function getTopic($topicPath)
{
$httpCallContext = new HttpCallContext();
$httpCallContext->setMethod(Resources::HTTP_GET);
$httpCallContext->setPath($topicPath);
$httpCallContext->addStatusCode(Resources::STATUS_OK);
$response = $this->sendHttpContext($httpCallContext);
$topicInfo = new TopicInfo();
$topicInfo->parseXml($response->getBody());
return $topicInfo;
}
/**
* Lists topics.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780744
*
* @param ListTopicsOptions $listTopicsOptions The options to list
* the topics
*
* @return ListTopicsResult
*/
public function listTopics(ListTopicsOptions $listTopicsOptions = null)
{
$response = $this->_listOptions(
$listTopicsOptions,
Resources::LIST_TOPICS_PATH
);
$listTopicsResult = new ListTopicsResult();
$listTopicsResult->parseXml($response->getBody());
return $listTopicsResult;
}
/**
* Creates a subscription with specified topic path and
* subscription info.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780748
*
* @param string $topicPath The path of
* the topic
* @param SubscriptionInfo $subscriptionInfo The information
* of the subscription
*
* @return SubscriptionInfo
*/
public function createSubscription($topicPath, SubscriptionInfo $subscriptionInfo)
{
$httpCallContext = new HttpCallContext();
$httpCallContext->setMethod(Resources::HTTP_PUT);
$subscriptionPath = sprintf(
Resources::SUBSCRIPTION_PATH,
$topicPath,
$subscriptionInfo->getTitle()
);
$httpCallContext->setPath($subscriptionPath);
$httpCallContext->addHeader(
Resources::CONTENT_TYPE,
Resources::ATOM_ENTRY_CONTENT_TYPE
);
$httpCallContext->addStatusCode(Resources::STATUS_CREATED);
$subscriptionDescriptionXml = XmlSerializer::objectSerialize(
$subscriptionInfo->getSubscriptionDescription(),
'SubscriptionDescription'
);
$entry = new Entry();
$content = new Content($subscriptionDescriptionXml);
$content->setType(Resources::XML_CONTENT_TYPE);
$entry->setContent($content);
$entry->setAttribute(
Resources::XMLNS,
Resources::SERVICE_BUS_NAMESPACE
);
$xmlWriter = new \XMLWriter();
$xmlWriter->openMemory();
$entry->writeXml($xmlWriter);
$httpCallContext->setBody($xmlWriter->outputMemory());
$response = $this->sendHttpContext($httpCallContext);
$subscriptionInfo = new SubscriptionInfo();
$subscriptionInfo->parseXml($response->getBody());
return $subscriptionInfo;
}
/**
* Deletes a subscription.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780740
*
* @param string $topicPath The path of the topic
* @param string $subscriptionName The name of the subscription
*/
public function deleteSubscription($topicPath, $subscriptionName)
{
$httpCallContext = new HttpCallContext();
$httpCallContext->setMethod(Resources::HTTP_DELETE);
$httpCallContext->addStatusCode(Resources::STATUS_OK);
$subscriptionPath = sprintf(
Resources::SUBSCRIPTION_PATH,
$topicPath,
$subscriptionName
);
$httpCallContext->setPath($subscriptionPath);
$this->sendHttpContext($httpCallContext);
}
/**
* Gets a subscription.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780741
*
* @param string $topicPath The path of the topic
* @param string $subscriptionName The name of the subscription
*
* @return SubscriptionInfo
*/
public function getSubscription($topicPath, $subscriptionName)
{
$httpCallContext = new HttpCallContext();
$httpCallContext->setMethod(Resources::HTTP_GET);
$httpCallContext->addStatusCode(Resources::STATUS_OK);
$subscriptionPath = sprintf(
Resources::SUBSCRIPTION_PATH,
$topicPath,
$subscriptionName
);
$httpCallContext->setPath($subscriptionPath);
$response = $this->sendHttpContext($httpCallContext);
$subscriptionInfo = new SubscriptionInfo();
$subscriptionInfo->parseXml($response->getBody());
return $subscriptionInfo;
}
/**
* Lists subscription.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780766
*
* @param string $topicPath The path of
* the topic
* @param ListSubscriptionsOptions|null $listSubscriptionsOptions The options
* to list the subscription
*
* @return ListSubscriptionsResult
*/
public function listSubscriptions(
$topicPath,
ListSubscriptionsOptions $listSubscriptionsOptions = null
) {
$listSubscriptionsPath = sprintf(
Resources::LIST_SUBSCRIPTIONS_PATH,
$topicPath
);
$response = $this->_listOptions(
$listSubscriptionsOptions,
$listSubscriptionsPath
);
$listSubscriptionsResult = new ListSubscriptionsResult();
$listSubscriptionsResult->parseXml($response->getBody());
return $listSubscriptionsResult;
}
/**
* Creates a rule.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780774
*
* @param string $topicPath The path of the topic
* @param string $subscriptionName The name of the subscription
* @param RuleInfo $ruleInfo The information of the rule
*
* @return RuleInfo
*/
public function createRule($topicPath, $subscriptionName, RuleInfo $ruleInfo)
{
$httpCallContext = new HttpCallContext();
$httpCallContext->setMethod(Resources::HTTP_PUT);
$httpCallContext->addStatusCode(Resources::STATUS_CREATED);
$httpCallContext->addHeader(
Resources::CONTENT_TYPE,
Resources::ATOM_ENTRY_CONTENT_TYPE
);
$rulePath = sprintf(
Resources::RULE_PATH,
$topicPath,
$subscriptionName,
$ruleInfo->getTitle()
);
$ruleDescriptionXml = XmlSerializer::objectSerialize(
$ruleInfo->getRuleDescription(),
'RuleDescription'
);
$entry = new Entry();
$content = new Content($ruleDescriptionXml);
$content->setType(Resources::XML_CONTENT_TYPE);
$entry->setContent($content);
$entry->setAttribute(
Resources::XMLNS,
Resources::SERVICE_BUS_NAMESPACE
);
$xmlWriter = new \XMLWriter();
$xmlWriter->openMemory();
$entry->writeXml($xmlWriter);
$httpCallContext->setBody($xmlWriter->outputMemory());
$httpCallContext->setPath($rulePath);
$response = $this->sendHttpContext($httpCallContext);
$ruleInfo = new ruleInfo();
$ruleInfo->parseXml($response->getBody());
return $ruleInfo;
}
/**
* Deletes a rule.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780751
*
* @param string $topicPath The path of the topic
* @param string $subscriptionName The name of the subscription
* @param string $ruleName The name of the rule
*/
public function deleteRule($topicPath, $subscriptionName, $ruleName)
{
$httpCallContext = new HttpCallContext();
$httpCallContext->addStatusCode(Resources::STATUS_OK);
$httpCallContext->setMethod(Resources::HTTP_DELETE);
$rulePath = sprintf(
Resources::RULE_PATH,
$topicPath,
$subscriptionName,
$ruleName
);
$httpCallContext->setPath($rulePath);
$this->sendHttpContext($httpCallContext);
}
/**
* Gets a rule.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780772
*
* @param string $topicPath The path of the topic
* @param string $subscriptionName The name of the subscription
* @param string $ruleName The name of the rule
*
* @return RuleInfo
*/
public function getRule($topicPath, $subscriptionName, $ruleName)
{
$httpCallContext = new HttpCallContext();
$httpCallContext->setMethod(Resources::HTTP_GET);
$httpCallContext->addStatusCode(Resources::STATUS_OK);
$rulePath = sprintf(
Resources::RULE_PATH,
$topicPath,
$subscriptionName,
$ruleName
);
$httpCallContext->setPath($rulePath);
$response = $this->sendHttpContext($httpCallContext);
$ruleInfo = new RuleInfo();
$ruleInfo->parseXml($response->getBody());
return $ruleInfo;
}
/**
* Lists rules.
*
* @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780732
*
* @param string $topicPath The path of the topic
* @param string $subscriptionName The name of the subscription
* @param ListRulesOptions|null $listRulesOptions The options to list the rules
*
* @return ListRulesResult
*/
public function listRules(
$topicPath,
$subscriptionName,
ListRulesOptions $listRulesOptions = null
) {
$listRulesPath = sprintf(
Resources::LIST_RULES_PATH,
$topicPath,
$subscriptionName
);
$response = $this->_listOptions(
$listRulesOptions,
$listRulesPath
);
$listRulesResult = new ListRulesResult();
$listRulesResult->parseXml($response->getBody());
return $listRulesResult;
}
}