/**
  * 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;
 }
 /** 
  * Sets the title. 
  * 
  * @param string $title The title of the rule info.
  * 
  * @return none
  */
 public function setTitle($title)
 {
     $this->_entry->setTitle($title);
 }
Example #3
0
 /**
  * Processes entry node.
  *
  * @param array $xmlArray An array of simple xml elements.
  *
  * @return array
  */
 protected function processEntryNode($xmlArray)
 {
     $entry = array();
     $entryItem = $xmlArray[Resources::ENTRY];
     if (is_array($entryItem)) {
         foreach ($xmlArray[Resources::ENTRY] as $entryXmlInstance) {
             $entryInstance = new Entry();
             $entryInstance->fromXml($entryXmlInstance);
             $entry[] = $entryInstance;
         }
     } else {
         $entryInstance = new Entry();
         $entryInstance->fromXml($entryItem);
         $entry[] = $entryInstance;
     }
     return $entry;
 }
 /**
  * Create a job.
  *
  * @param WindowsAzure\MediaServices\Models\JobTemplate $jobTemplate   Job
  * template data
  *
  * @param array                                         $taskTemplates Performed
  * tasks template array
  *
  * @return Models\JobTemplate
  */
 public function createJobTemplate($jobTemplate, $taskTemplates)
 {
     Validate::isA($jobTemplate, 'WindowsAzure\\MediaServices\\Models\\JobTemplate', 'jobTemplate');
     Validate::isArray($taskTemplates, 'taskTemplates');
     $batch = new BatchRequest();
     $batch->appendContext($this->_getCreateEmptyJobTemplateContext($jobTemplate));
     if ($taskTemplates != null) {
         foreach ($taskTemplates as $taskTemplate) {
             $batch->appendContext($this->_getCreateTaskTemplateContext($taskTemplate));
         }
     }
     $batch->encode();
     $method = Resources::HTTP_POST;
     $headers = $batch->getHeaders();
     $postParams = array();
     $queryParams = array();
     $path = '$batch';
     $statusCode = Resources::STATUS_ACCEPTED;
     $body = $batch->getBody();
     $response = $this->send($method, $headers, $postParams, $queryParams, $path, $statusCode, $body);
     $batchResponse = new BatchResponse($response->getBody(), $batch);
     $responses = $batchResponse->getContexts();
     $jobTemplateResponse = $responses[0];
     $entry = new Entry();
     $entry->parseXml($jobTemplateResponse->getBody());
     $properties = $this->getPropertiesFromAtomEntry($entry);
     return JobTemplate::createFromOptions($properties);
 }
 /**
  * @covers WindowsAzure\Common\Internal\Atom\Entry::fromXml
  */
 public function testFromXml()
 {
     // Setup
     $xmlString = '<entry>
                    <content>
                    </content>
                   </entry>';
     $entry = new Entry();
     $xml = simplexml_load_string($xmlString);
     // Test
     $entry->fromXml($xml);
     // Assert
     $this->assertNotNull($entry->getContent());
 }