/** * Creates ListBlobsResult object from parsed XML response. * * @param array $parsed XML response parsed into array. * * @return ListBlobsResult */ public static function create($parsed) { $result = new ListBlobsResult(); $result->_containerName = Utilities::tryGetKeysChainValue($parsed, Resources::XTAG_ATTRIBUTES, Resources::XTAG_CONTAINER_NAME); $result->_prefix = Utilities::tryGetValue($parsed, Resources::QP_PREFIX); $result->_marker = Utilities::tryGetValue($parsed, Resources::QP_MARKER); $result->_nextMarker = Utilities::tryGetValue($parsed, Resources::QP_NEXT_MARKER); $result->_maxResults = intval(Utilities::tryGetValue($parsed, Resources::QP_MAX_RESULTS, 0)); $result->_delimiter = Utilities::tryGetValue($parsed, Resources::QP_DELIMITER); $result->_blobs = array(); $result->_blobPrefixes = array(); $rawBlobs = array(); $rawBlobPrefixes = array(); if (is_array($parsed['Blobs']) && array_key_exists('Blob', $parsed['Blobs'])) { $rawBlobs = Utilities::getArray($parsed['Blobs']['Blob']); } foreach ($rawBlobs as $value) { $blob = new Blob(); $blob->setName($value['Name']); $blob->setUrl($value['Url']); $blob->setSnapshot(Utilities::tryGetValue($value, 'Snapshot')); $blob->setProperties(BlobProperties::create(Utilities::tryGetValue($value, 'Properties'))); $blob->setMetadata(Utilities::tryGetValue($value, Resources::QP_METADATA, array())); $result->_blobs[] = $blob; } if (is_array($parsed['Blobs']) && array_key_exists('BlobPrefix', $parsed['Blobs'])) { $rawBlobPrefixes = Utilities::getArray($parsed['Blobs']['BlobPrefix']); } foreach ($rawBlobPrefixes as $value) { $blobPrefix = new BlobPrefix(); $blobPrefix->setName($value['Name']); $result->_blobPrefixes[] = $blobPrefix; } return $result; }
/** * Creates ListBlobResult object from parsed XML response. * * @param array $parsedResponse XML response parsed into array. * * @return ListBlobResult */ public static function create($parsedResponse) { $result = new ListContainersResult(); $result->_accountName = Utilities::tryGetKeysChainValue($parsedResponse, Resources::XTAG_ATTRIBUTES, Resources::XTAG_ACCOUNT_NAME); $result->_prefix = Utilities::tryGetValue($parsedResponse, Resources::QP_PREFIX); $result->_marker = Utilities::tryGetValue($parsedResponse, Resources::QP_MARKER); $result->_nextMarker = Utilities::tryGetValue($parsedResponse, Resources::QP_NEXT_MARKER); $result->_maxResults = Utilities::tryGetValue($parsedResponse, Resources::QP_MAX_RESULTS); $result->_containers = array(); $rawContainer = array(); if (!empty($parsedResponse['Containers'])) { $containersArray = $parsedResponse['Containers']['Container']; $rawContainer = Utilities::getArray($containersArray); } foreach ($rawContainer as $value) { $container = new Container(); $container->setName($value['Name']); $container->setUrl($value['Url']); $container->setMetadata(Utilities::tryGetValue($value, Resources::QP_METADATA, array())); $properties = new ContainerProperties(); $date = $value['Properties']['Last-Modified']; $date = Utilities::rfc1123ToDateTime($date); $properties->setLastModified($date); $properties->setETag($value['Properties']['Etag']); $container->setProperties($properties); $result->_containers[] = $container; } return $result; }
/** * Constructs new hosted service object. */ public function __construct() { $sources = func_get_args(); parent::__construct($sources); $this->_deployments = array(); foreach ($sources as $source) { $deployments = Utilities::tryGetKeysChainValue($source, Resources::XTAG_DEPLOYMENTS, Resources::XTAG_DEPLOYMENT); if (!empty($deployments)) { $this->_deployments = Utilities::createInstanceList(Utilities::getArray($deployments), 'WindowsAzure\\ServiceManagement\\Models\\Deployment'); } } }
/** * Constructs new storage service object. */ public function __construct() { $sources = func_get_args(); parent::__construct($sources); foreach ($sources as $source) { $this->setStatus(Utilities::tryGetValue($source, Resources::XTAG_STATUS, $this->getStatus())); $endpoints = Utilities::tryGetKeysChainValue($source, Resources::XTAG_ENDPOINTS, Resources::XTAG_ENDPOINT); $this->setBlobEndpointUri(Utilities::tryGetValue($endpoints, 0)); $this->setQueueEndpointUri(Utilities::tryGetValue($endpoints, 1)); $this->setTableEndpointUri(Utilities::tryGetValue($endpoints, 2)); } }
/** * Creates ListQueuesResult object from parsed XML response. * * @param array $parsedResponse XML response parsed into array. * * @return WindowsAzure\Queue\Models\ListQueuesResult. */ public static function create($parsedResponse) { $result = new ListQueuesResult(); $result->_accountName = Utilities::tryGetKeysChainValue($parsedResponse, Resources::XTAG_ATTRIBUTES, Resources::XTAG_ACCOUNT_NAME); $result->_prefix = Utilities::tryGetValue($parsedResponse, Resources::QP_PREFIX); $result->_marker = Utilities::tryGetValue($parsedResponse, Resources::QP_MARKER); $result->_nextMarker = Utilities::tryGetValue($parsedResponse, Resources::QP_NEXT_MARKER); $result->_maxResults = Utilities::tryGetValue($parsedResponse, Resources::QP_MAX_RESULTS); $result->_queues = array(); $rawQueues = array(); if (!empty($parsedResponse['Queues'])) { $rawQueues = Utilities::getArray($parsedResponse['Queues']['Queue']); } foreach ($rawQueues as $value) { $queue = new Queue($value['Name'], $value['Url']); $metadata = Utilities::tryGetValue($value, Resources::QP_METADATA); $queue->setMetadata(is_null($metadata) ? array() : $metadata); $result->_queues[] = $queue; } return $result; }
/** * Translates the current instance info. * * @param string $environmentInfo The environment info. * * @return RoleInstance */ private function _translateCurrentInstance($environmentInfo) { $endpoints = array(); $endpointsInfo = Utilities::tryGetKeysChainValue($environmentInfo, 'CurrentInstance', 'Endpoints', 'Endpoint'); if (!is_null($endpointsInfo)) { $endpoints = $this->_translateRoleInstanceEndpoints($endpointsInfo); } $currentInstance = new RoleInstance($environmentInfo['CurrentInstance']['@attributes']['id'], $environmentInfo['CurrentInstance']['@attributes']['faultDomain'], $environmentInfo['CurrentInstance']['@attributes']['updateDomain'], $endpoints); foreach ($currentInstance->getInstanceEndpoints() as $endpoint) { $endpoint->setRoleInstance($currentInstance); } return $currentInstance; }
/** * @covers WindowsAzure\Common\Internal\Utilities::tryGetKeysChainValue */ public function testTryGetKeysChainValue() { // Setup $array = array(); $array['a1'] = array(); $array['a2'] = 'value1'; $array['a1']['b1'] = array(); $array['a1']['b2'] = 'value2'; $array['a1']['b1']['c1'] = 'value3'; // Test - Level 1 $this->assertEquals('value1', Utilities::tryGetKeysChainValue($array, 'a2')); $this->assertEquals(null, Utilities::tryGetKeysChainValue($array, 'a3')); // Test - Level 2 $this->assertEquals('value2', Utilities::tryGetKeysChainValue($array, 'a1', 'b2')); $this->assertEquals(null, Utilities::tryGetKeysChainValue($array, 'a1', 'b3')); // Test - Level 3 $this->assertEquals('value3', Utilities::tryGetKeysChainValue($array, 'a1', 'b1', 'c1')); $this->assertEquals(null, Utilities::tryGetKeysChainValue($array, 'a1', 'b1', 'c2')); }
/** * Creates a new Deployment from parsed response body. * * @param array $parsed The parsed response body in array representation. * * @return Deployment */ public static function create($parsed) { $result = new Deployment(); $name = Utilities::tryGetValue($parsed, Resources::XTAG_NAME); $label = Utilities::tryGetValue($parsed, Resources::XTAG_LABEL); $url = Utilities::tryGetValue($parsed, Resources::XTAG_URL); $locked = Utilities::tryGetValue($parsed, Resources::XTAG_LOCKED); $rollbackAllowed = Utilities::tryGetValue($parsed, Resources::XTAG_ROLLBACK_ALLOWED); $sdkVersion = Utilities::tryGetValue($parsed, Resources::XTAG_SDK_VERSION); $inputEndpointList = Utilities::tryGetKeysChainValue($parsed, Resources::XTAG_INPUT_ENDPOINT_LIST, Resources::XTAG_INPUT_ENDPOINT); $roleList = Utilities::tryGetKeysChainValue($parsed, Resources::XTAG_ROLE_LIST, Resources::XTAG_ROLE); $roleInstanceList = Utilities::tryGetKeysChainValue($parsed, Resources::XTAG_ROLE_INSTANCE_LIST, Resources::XTAG_ROLE_INSTANCE); $status = Utilities::tryGetValue($parsed, Resources::XTAG_STATUS); $slot = Utilities::tryGetValue($parsed, Resources::XTAG_DEPLOYMENT_SLOT); $privateId = Utilities::tryGetValue($parsed, Resources::XTAG_PRIVATE_ID); $configuration = Utilities::tryGetValue($parsed, Resources::XTAG_CONFIGURATION); $upgradeDomainCount = Utilities::tryGetValue($parsed, Resources::XTAG_UPGRADE_DOMAIN_COUNT); $upgradeStatus = Utilities::tryGetValue($parsed, Resources::XTAG_UPGRADE_STATUS); $result->setConfiguration($configuration); $result->setLabel($label); $result->setLocked(Utilities::toBoolean($locked)); $result->setName($name); $result->setPrivateId($privateId); $result->setRollbackAllowed(Utilities::toBoolean($rollbackAllowed)); $result->setSdkVersion($sdkVersion); $result->setSlot($slot); $result->setStatus($status); $result->setUpgradeDomainCount(intval($upgradeDomainCount)); $result->setUpgradeStatus(UpgradeStatus::create($upgradeStatus)); $result->setUrl($url); $result->setRoleInstanceList(Utilities::createInstanceList(Utilities::getArray($roleInstanceList), 'WindowsAzure\\ServiceManagement\\Models\\RoleInstance')); $result->setRoleList(Utilities::createInstanceList(Utilities::getArray($roleList), 'WindowsAzure\\ServiceManagement\\Models\\Role')); $result->setInputEndpointList(Utilities::createInstanceList(Utilities::getArray($inputEndpointList), 'WindowsAzure\\ServiceManagement\\Models\\InputEndpoint')); return $result; }