예제 #1
0
 /**
  * Creates an RuleInfo with specified parameters.
  *
  * @param string          $title           The title of the rule.
  * @param RuleDescription $ruleDescription The description of the rule.
  */
 public function __construct($title = Resources::EMPTY_STRING, $ruleDescription = null)
 {
     Validate::isString($title, 'title');
     if (is_null($ruleDescription)) {
         $ruleDescription = new RuleDescription();
     }
     $this->_ruleDescription = $ruleDescription;
     $this->_entry = new Entry();
     $this->_entry->setTitle($title);
     $this->_entry->setAttribute(Resources::XMLNS, Resources::SERVICE_BUS_NAMESPACE);
 }
 /**
  * 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)
 {
     $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->sendContext($httpCallContext);
     $ruleInfo = new ruleInfo();
     $ruleInfo->parseXml($response->getBody());
     return $ruleInfo;
 }