/**
  * @covers WindowsAzure\Queue\Models\QueueMessage::toXml
  */
 public function testToXml()
 {
     // Setup
     $queueMessage = new QueueMessage();
     $messageText = 'this is message text';
     $array = array('MessageText' => $messageText);
     $queueMessage->setMessageText($messageText);
     $xmlSerializer = new XmlSerializer();
     $properties = array(XmlSerializer::ROOT_NAME => QueueMessage::$xmlRootName);
     $expected = $xmlSerializer->serialize($array, $properties);
     // Test
     $actual = $queueMessage->toXml($xmlSerializer);
     // Assert
     $this->assertEquals($expected, $actual);
 }
 /**
  * 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;
 }
Пример #3
0
 /**
  * Converts the  BlockList object to XML representation
  * 
  * @param XmlSerializer $xmlSerializer The XML serializer.
  * 
  * @return string
  */
 public function toXml($xmlSerializer)
 {
     $properties = array(XmlSerializer::ROOT_NAME => self::$xmlRootName);
     $array = array();
     foreach ($this->_entries as $value) {
         $array[] = array($value->getType() => base64_encode($value->getBlockId()));
     }
     return $xmlSerializer->serialize($array, $properties);
 }
Пример #4
0
 /**
  * Writes an XML string representing the rule info instance. 
  * 
  * @param XMLWriter $xmlWriter The XML writer. 
  * 
  * @return none
  */
 public function writeXml($xmlWriter)
 {
     $content = null;
     if (!is_null($this->_ruleDescription)) {
         $content = new Content();
         $content->setText(XmlSerializer::objectSerialize($this->_ruleDescription, 'RuleDescription'));
     }
     $this->_entry->setContent($content);
     $this->_entry->writeXml($xmlWriter);
 }
 /**
  * @covers WindowsAzure\Common\Internal\Serialization\XmlSerializer::objectSerialize
  */
 public function testObjectSerializeInvalidObject()
 {
     // Setup
     $this->setExpectedException(get_class(new \InvalidArgumentException()));
     // Test
     $actual = XmlSerializer::objectSerialize(null, null);
     // Assert
 }
Пример #6
0
 /**
  * Returns a XML string based on ATOM ENTRY schema. 
  * 
  * @param \XMLWriter $xmlWriter The XML writer.
  *
  * @return none
  */
 public function writeXml($xmlWriter)
 {
     $content = null;
     if (!is_null($this->_queueDescription)) {
         $content = new Content();
         $content->setText(XmlSerializer::objectSerialize($this->_queueDescription, 'QueueDescription'));
         $content->setType(Resources::XML_CONTENT_TYPE);
     }
     $this->_entry->setContent($content);
     $this->_entry->writeXml($xmlWriter);
 }
Пример #7
0
 /** 
  * Serialize an object with specified root element name. 
  * 
  * @param object $targetObject The target object. 
  * @param string $rootName     The name of the root element. 
  * 
  * @return string
  */
 public static function objectSerialize($targetObject, $rootName)
 {
     Validate::notNull($targetObject, 'targetObject');
     Validate::isString($rootName, 'rootName');
     $xmlWriter = new \XmlWriter();
     $xmlWriter->openMemory();
     $xmlWriter->setIndent(true);
     $reflectionClass = new \ReflectionClass($targetObject);
     $methodArray = $reflectionClass->getMethods();
     $attributes = self::_getInstanceAttributes($targetObject, $methodArray);
     $xmlWriter->startElement($rootName);
     if (!is_null($attributes)) {
         foreach (array_keys($attributes) as $attributeKey) {
             $xmlWriter->writeAttribute($attributeKey, $attributes[$attributeKey]);
         }
     }
     foreach ($methodArray as $method) {
         if (strpos($method->name, 'get') === 0 && $method->isPublic() && $method->name != 'getAttributes') {
             $variableName = substr($method->name, 3);
             $variableValue = $method->invoke($targetObject);
             if (!empty($variableValue)) {
                 if (gettype($variableValue) === 'object') {
                     $xmlWriter->writeRaw(XmlSerializer::objectSerialize($variableValue, $variableName));
                 } else {
                     $xmlWriter->writeElement($variableName, $variableValue);
                 }
             }
         }
     }
     $xmlWriter->endElement();
     return $xmlWriter->outputMemory(true);
 }
Пример #8
0
 /**
  * Converts this current object to XML representation.
  * 
  * @param XmlSerializer $xmlSerializer The XML serializer.
  * 
  * @return string. 
  */
 public function toXml($xmlSerializer)
 {
     $array = array('MessageText' => $this->_messageText);
     $properties = array(XmlSerializer::ROOT_NAME => self::$xmlRootName);
     return $xmlSerializer->serialize($array, $properties);
 }
Пример #9
0
 /**
  * Creates new channel and removes existing channel files by:
  * 1) Removes existing channel files on the cloud.
  * 2) Constructs pirum.xml contents.
  * 3) Cleans previous files if any and create new channel directory.
  * 4) Writes pirum.xml.
  * 5) Generates the channel files.
  *
  * @return none
  */
 private static function _createNewChannel()
 {
     echo "Removing old channel files if any...\n";
     self::_clearContainer(CHANNEL_MAIN_CONTAINER, self::$_blobRestProxy);
     self::_clearContainer(CHANNEL_GET_CONTAINER, self::$_blobRestProxy);
     self::_clearContainer(CHANNEL_REST_CONTAINER, self::$_blobRestProxy);
     $xmlSerializer = new XmlSerializer();
     $properties = array(XmlSerializer::ROOT_NAME => 'server');
     $fileArray = array('name' => CHANNEL_NAME, 'summary' => CHANNEL_SUMMARY, 'alias' => CHANNEL_ALIAS, 'url' => CHANNEL_URL);
     $fileContents = $xmlSerializer->serialize($fileArray, $properties);
     $dirName = CHANNEL_DIR_NAME;
     self::_createDir(CHANNEL_DIR_NAME);
     $filePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . $dirName;
     $filePath .= DIRECTORY_SEPARATOR . 'pirum.xml';
     file_put_contents($filePath, $fileContents);
     self::_executeCommand("pirum build {$dirName}/");
 }
Пример #10
0
 /**
  * Converts this current object to XML representation.
  * 
  * @param XmlSerializer $xmlSerializer The XML serializer.
  * 
  * @return string
  */
 public function toXml($xmlSerializer)
 {
     $properties = array(XmlSerializer::ROOT_NAME => self::$xmlRootName);
     return $xmlSerializer->serialize($this->toArray(), $properties);
 }
Пример #11
0
 /**
  * @covers WindowsAzure\Common\Internal\Serialization\XmlSerializer::serialize
  * @covers WindowsAzure\Common\Internal\Serialization\XmlSerializer::_arr2xml
  */
 public function testSerializeAttribute()
 {
     // Setup
     $xmlSerializer = new XmlSerializer();
     $expected = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<Object field1="value1" field2="value2"/>' . "\n";
     $object = array('@attributes' => array('field1' => 'value1', 'field2' => 'value2'));
     $serializerProperties = array(XmlSerializer::ROOT_NAME => 'Object');
     // Test
     $actual = $xmlSerializer->serialize($object, $serializerProperties);
     $this->assertEquals($expected, $actual);
 }
Пример #12
0
 /**
  * Converts this current object to XML representation.
  * 
  * @param XmlSerializer $xmlSerializer The XML serializer.
  * 
  * @return string.
  */
 public function toXml($xmlSerializer)
 {
     $properties = array(XmlSerializer::DEFAULT_TAG => 'SignedIdentifier', XmlSerializer::ROOT_NAME => self::$xmlRootName);
     return $xmlSerializer->serialize($this->toArray(), $properties);
 }