/** * Creates GetHostedServicePropertiesResult from parsed response. * * @param array $parsed The parsed response in array representation. * * @return GetHostedServicePropertiesResult */ public static function create($parsed) { $result = new GetHostedServicePropertiesResult(); $properties = Utilities::tryGetValue($parsed, Resources::XTAG_HOSTED_SERVICE_PROPERTIES); $result->_hostedService = new HostedService($parsed, $properties); return $result; }
/** * Creates GetStorageServicePropertiesResult from parsed response. * * @param array $parsed The parsed response in array representation. * * @return GetStorageServicePropertiesResult */ public static function create($parsed) { $result = new GetStorageServicePropertiesResult(); $properties = Utilities::tryGetValue($parsed, Resources::XTAG_STORAGE_SERVICE_PROPERTIES); $result->_storageService = new StorageService($parsed, $properties); return $result; }
/** * Creates ListBlobResult object from parsed XML response. * * @param array $parsedResponse XML response parsed into array. * * @return WindowsAzure\Blob\Models\ListBlobResult. */ public static function create($parsedResponse) { $result = new ListContainersResult(); $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 affinity group object. */ public function __construct() { $sources = func_get_args(); parent::__construct($sources); foreach ($sources as $source) { $this->setName(Utilities::tryGetValue($source, Resources::XTAG_NAME, $this->getName())); } }
/** * Creates WrapAccesTokenResult object from parsed XML response. * * @param array $response The get WRAP access token response. * * @return WindowsAzure\ServiceBus\Internal\WrapAccessTokenResult. */ public static function create($response) { $wrapAccessTokenResult = new self(); parse_str($response, $parsedResponse); $wrapAccessTokenResult->setAccessToken(Utilities::tryGetValue($parsedResponse, Resources::WRAP_ACCESS_TOKEN)); $wrapAccessTokenResult->setExpiresIn(Utilities::tryGetValue($parsedResponse, Resources::WRAP_ACCESS_TOKEN_EXPIRES_IN)); return $wrapAccessTokenResult; }
/** * Creates new QueryTablesResult object * * @param array $headers The HTTP response headers * @param array $entries The table entriess * * @return \WindowsAzure\Table\Models\QueryTablesResult */ public static function create($headers, $entries) { $result = new QueryTablesResult(); $headers = array_change_key_case($headers); $result->setNextTableName(Utilities::tryGetValue($headers, Resources::X_MS_CONTINUATION_NEXTTABLENAME)); $result->setTables($entries); return $result; }
/** * Create InsertEntityResult object from HTTP response parts. * * @param string $body The HTTP response body. * @param array $headers The HTTP response headers. * @param IAtomReaderWriter $atomSerializer The atom reader and writer. * * @return \WindowsAzure\Table\Models\InsertEntityResult * * @static */ public static function create($body, $headers, $atomSerializer) { $result = new InsertEntityResult(); $entity = $atomSerializer->parseEntity($body); $entity->setETag(Utilities::tryGetValue($headers, Resources::ETAG)); $result->setEntity($entity); return $result; }
/** * Creates new GetStorageServiceKeysResult object from parsed response. * * @param array $parsed The HTTP parsed response into array representation. * * @return GetStorageServiceKeysResult */ public static function create($parsed) { $result = new GetStorageServiceKeysResult(); $keys = Utilities::tryGetValue($parsed, Resources::XTAG_STORAGE_SERVICE_KEYS); $result->_url = Utilities::tryGetValue($parsed, Resources::XTAG_URL); $result->_primary = Utilities::tryGetValue($keys, Resources::XTAG_PRIMARY); $result->_secondary = Utilities::tryGetValue($keys, Resources::XTAG_SECONDARY); return $result; }
/** * Constructs new storage service object. * * @param array $sources The list of sources that has the row XML. */ public function __construct($sources = array()) { parent::__construct($sources); foreach ($sources as $source) { $this->setName(Utilities::tryGetValue($source, Resources::XTAG_SERVICE_NAME, $this->getName())); $this->setAffinityGroup(Utilities::tryGetValue($source, Resources::XTAG_AFFINITY_GROUP, $this->getAffinityGroup())); $this->setUrl(Utilities::tryGetValue($source, Resources::XTAG_URL, $this->getUrl())); } }
/** * Creates a new Role from parsed response body. * * @param array $parsed The parsed response body in array representation. * * @return Role */ public static function create($parsed) { $role = new Role(); $roleName = Utilities::tryGetValue($parsed, Resources::XTAG_ROLE_NAME); $osVersion = Utilities::tryGetValue($parsed, Resources::XTAG_OS_VERSION); $role->setOsVersion($osVersion); $role->setRoleName($roleName); return $role; }
/** * @covers WindowsAzure\Common\Internal\Utilities::tryGetValue */ public function testTryGetValueWithNull() { // Setup $key = 10; $data = array(10, 20, 30); // Test $actual = Utilities::tryGetValue($data, $key); $this->assertNull($actual); }
/** * 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::tryGetValue($source, Resources::XTAG_ENDPOINTS); $this->setEndpoints(Utilities::tryGetValue($endpoints, Resources::XTAG_ENDPOINT, $this->getEndpoints())); } }
/** * Creates new QueryEntitiesResult instance. * * @param array $headers The HTTP response headers. * @param array $entities The entities. * * @return QueryEntitiesResult */ public static function create($headers, $entities) { $result = new QueryEntitiesResult(); $headers = array_change_key_case($headers); $nextPK = Utilities::tryGetValue($headers, Resources::X_MS_CONTINUATION_NEXTPARTITIONKEY); $nextRK = Utilities::tryGetValue($headers, Resources::X_MS_CONTINUATION_NEXTROWKEY); $result->setEntities($entities); $result->setNextPartitionKey($nextPK); $result->setNextRowKey($nextRK); return $result; }
/** * Creates a new UpgradeStatus object from the parsed response. * * @param array $parsed The parsed response body in array representation * * @return \WindowsAzure\ServiceManagement\Models\UpgradeStatus */ public static function create($parsed) { $result = new self(); $upgradeType = Utilities::tryGetValue($parsed, Resources::XTAG_UPGRADE_TYPE); $currentUpgradeDomainState = Utilities::tryGetValue($parsed, Resources::XTAG_CURRENT_UPGRADE_DOMAIN_STATE); $currentUpgradeDomain = Utilities::tryGetValue($parsed, Resources::XTAG_CURRENT_UPGRADE_DOMAIN); $result->setCurrentUpgradeDomain(intval($currentUpgradeDomain)); $result->setCurrentUpgradeDomainState($currentUpgradeDomainState); $result->setUpgradeType($upgradeType); return $result; }
/** * Computes the authorization signature for blob and queue shared key. * * @param array $headers request headers. * @param string $url reuqest url. * @param array $queryParams query variables. * @param string $httpMethod request http method. * * @see Blob and Queue Services (Shared Key Authentication) at * http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx * * @return string */ protected function computeSignature($headers, $url, $queryParams, $httpMethod) { $canonicalizedResource = parent::computeCanonicalizedResourceForTable($url, $queryParams); $stringToSign = array(); foreach ($this->includedHeaders as $header) { $stringToSign[] = Utilities::tryGetValue($headers, $header); } $stringToSign[] = $canonicalizedResource; $stringToSign = implode("\n", $stringToSign); return $stringToSign; }
/** * Creates BatchError object. * * @param WindowsAzure\Common\ServiceException $error The error object. * @param array $headers The response headers. * * @return \WindowsAzure\Table\Models\BatchError */ public static function create($error, $headers) { Validate::isTrue($error instanceof ServiceException, Resources::INVALID_EXC_OBJ_MSG); Validate::isArray($headers, 'headers'); $result = new BatchError(); $clean = array_change_key_case($headers); $result->setError($error); $contentId = Utilities::tryGetValue($clean, Resources::CONTENT_ID); $result->setContentId(is_null($contentId) ? null : intval($contentId)); return $result; }
/** * Creates CreateFileRangeResult object from $parsed response in array * representation * * @param array $headers HTTP response headers * * @return CreateFileRangeResult */ public static function create($headers) { $result = new CreateFileRangeResult(); $clean = array_change_key_case($headers); $date = $clean[Resources::LAST_MODIFIED]; $date = Utilities::rfc1123ToDateTime($date); $result->setETag($clean[Resources::ETAG]); $result->setLastModified($date); $result->setContentMD5(Utilities::tryGetValue($clean, Resources::CONTENT_MD5)); return $result; }
/** * Creates a new InputEndpoint from parsed response body. * * @param array $parsed The parsed response body in array representation. * * @return InputEndpoint */ public static function create($parsed) { $inputEndpoint = new self(); $vip = Utilities::tryGetValue($parsed, Resources::XTAG_VIP); $port = Utilities::tryGetValue($parsed, Resources::XTAG_PORT); $roleName = Utilities::tryGetValue($parsed, Resources::XTAG_ROLE_NAME); $inputEndpoint->setPort($port); $inputEndpoint->setRoleName($roleName); $inputEndpoint->setVip($vip); return $inputEndpoint; }
/** * Creates CreateBlobPagesResult object from $parsed response in array * representation * * @param array $headers HTTP response headers * * @return CreateBlobPagesResult */ public static function create($headers) { $result = new CreateBlobPagesResult(); $clean = array_change_key_case($headers); $date = $clean[Resources::LAST_MODIFIED]; $date = Utilities::rfc1123ToDateTime($date); $result->setETag($clean[Resources::ETAG]); $result->setLastModified($date); $result->setContentMD5(Utilities::tryGetValue($clean, Resources::CONTENT_MD5)); $result->setSequenceNumber(intval(Utilities::tryGetValue($clean, Resources::X_MS_BLOB_SEQUENCE_NUMBER))); return $result; }
/** * 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 GetStorageServicePropertiesResult from parsed response. * * @param array $parsed The parsed response in array representation. * * @return GetStorageServicePropertiesResult */ public static function create($parsed) { $result = new GetStorageServicePropertiesResult(); $prop = Utilities::tryGetValue($parsed, Resources::XTAG_STORAGE_SERVICE_PROPERTIES); $result->_storageService = new StorageService($prop); $result->_storageService->setName(Utilities::tryGetValue($parsed, Resources::XTAG_SERVICE_NAME)); $result->_status = Utilities::tryGetValue($prop, Resources::XTAG_STATUS); $result->_url = Utilities::tryGetValue($parsed, Resources::XTAG_URL); $endpoints = Utilities::tryGetValue($prop, Resources::XTAG_ENDPOINTS); $result->_endpoints = Utilities::tryGetValue($endpoints, Resources::XTAG_ENDPOINT); return $result; }
/** * Creates new ListStorageServicesResult from parsed response body. * * @param array $parsed The parsed response body. * * @return ListStorageServicesResult */ public static function create($parsed) { $result = new ListStorageServicesResult(); $result->_storageServices = array(); $entries = Utilities::tryGetArray(Resources::XTAG_STORAGE_SERVICE, $parsed); foreach ($entries as $value) { $properties = new ServiceProperties(); $properties->setServiceName(Utilities::tryGetValue($value, Resources::XTAG_SERVICE_NAME)); $properties->setUrl(Utilities::tryGetValue($value, Resources::XTAG_URL)); $result->_storageServices[] = $properties; } return $result; }
/** * Creates GetOperationStatusResult object from parsed response. * * @param array $parsed The parsed response. * * @return GetOperationStatusResult */ public static function create($parsed) { $result = new GetOperationStatusResult(); $result->_id = Utilities::tryGetValue($parsed, Resources::XTAG_ID); $result->_status = Utilities::tryGetValue($parsed, Resources::XTAG_STATUS); $result->_httpStatusCode = Utilities::tryGetValue($parsed, Resources::XTAG_HTTP_STATUS_CODE); $error = Utilities::tryGetValue($parsed, Resources::XTAG_ERROR); if (!empty($error)) { $code = Utilities::tryGetValue($error, Resources::XTAG_CODE); $message = Utilities::tryGetValue($error, Resources::XTAG_MESSAGE); $result->_error = new ServiceException($code, $message); } return $result; }
/** * Creates new ListLocationsResult from parsed response body. * * @param array $parsed The parsed response body. * * @return ListLocationsResult */ public static function create($parsed) { $result = new ListLocationsResult(); $result->_locations = array(); $entries = array(); if (!empty($parsed)) { $entries = Utilities::getArray($parsed[Resources::XTAG_LOCATION]); } foreach ($entries as $value) { $location = new Location(); $location->setName(Utilities::tryGetValue($value, Resources::XTAG_NAME)); $location->setDisplayName(Utilities::tryGetValue($value, Resources::XTAG_DISPLAY_NAME)); $result->_locations[] = $location; } return $result; }
/** * 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->_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']); $queue->setMetadata(Utilities::tryGetValue($value, Resources::QP_METADATA, array())); $result->_queues[] = $queue; } return $result; }
/** * Creates GetAffinityGroupPropertiesResult from parsed response into array. * * @param array $parsed The parsed HTTP response body. * * @return GetAffinityGroupPropertiesResult */ public static function create($parsed) { $result = new GetAffinityGroupPropertiesResult(); $hostedServices = Utilities::tryGetArray(Resources::XTAG_HOSTED_SERVICES, $parsed); $storageServices = Utilities::tryGetArray(Resources::XTAG_STORAGE_SERVICES, $parsed); $result->_affinityGroup = new AffinityGroup($parsed); foreach ($hostedServices as $value) { $service = new ServiceProperties(); $service->setServiceName(Utilities::tryGetValue($value, Resources::XTAG_SERVICE_NAME)); $service->setUrl(Utilities::tryGetValue($value, Resources::XTAG_URL)); $result->_hostedServices[] = $service; } foreach ($storageServices as $value) { $service = new ServiceProperties(); $service->setServiceName(Utilities::tryGetValue($value, Resources::XTAG_SERVICE_NAME)); $service->setUrl(Utilities::tryGetValue($value, Resources::XTAG_URL)); $result->_storageServices[] = $service; } return $result; }
/** * Computes the authorization signature for file shared key. * * @param array $headers request headers. * @param string $url reuqest url. * @param array $queryParams query variables. * @param string $httpMethod request http method. * * @see File Services (Shared Key Authentication) at * http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx * * @return string */ protected function computeSignature($headers, $url, $queryParams, $httpMethod) { $canonicalizedHeaders = parent::computeCanonicalizedHeaders($headers); $canonicalizedResource = parent::computeCanonicalizedResource($url, $queryParams); $stringToSign = array(); $stringToSign[] = strtoupper($httpMethod); foreach ($this->includedHeaders as $header) { $v = Utilities::tryGetValue($headers, $header); if ($header == Resources::CONTENT_LENGTH && $v == 0) { $v = ''; } $stringToSign[] = $v; } if (count($canonicalizedHeaders) > 0) { $stringToSign[] = implode("\n", $canonicalizedHeaders); } $stringToSign[] = $canonicalizedResource; $stringToSign = implode("\n", $stringToSign); return $stringToSign; }
/** * 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; }
protected function compareMessages($expectedMessage, $actualMessage, $customProperties = null) { $this->assertEquals($expectedMessage->getBody(), $actualMessage->getBody(), 'body'); $this->assertEquals($expectedMessage->getContentType(), $actualMessage->getContentType(), 'getContentType'); $this->assertEquals($expectedMessage->getCorrelationId(), $actualMessage->getCorrelationId(), 'getCorrelationId'); $this->assertEquals($expectedMessage->getDate(), $actualMessage->getDate(), 'getDate'); // Note: The DeliveryCount property is controled by the server, so cannot compare it. $this->assertTrue(is_int($actualMessage->getDeliveryCount()), 'is_int($actualMessage->getDeliveryCount)'); $this->assertEquals($expectedMessage->getLabel(), $actualMessage->getLabel(), 'getLabel'); // Note: The LockLocation property is controled by the server, so cannot compare it. $this->assertTrue(is_null($actualMessage->getLockLocation()) || is_string($actualMessage->getLockLocation()), 'is_string/numm($actualMessage->getLockLocation)'); // Note: The LockToken property is controled by the server, so cannot compare it. $this->assertTrue(is_null($actualMessage->getLockToken()) || is_string($actualMessage->getLockToken()), 'is_string/null($actualMessage->getLockToken)'); // Note: The LockedUntilUtc property is controled by the server, so cannot compare it. $this->assertTrue(is_null($actualMessage->getLockedUntilUtc()) || $actualMessage->getLockedUntilUtc() instanceof \DateTime, '$is_null/DateTime(actualMessage->getLockedUntilUtc)'); $this->assertEquals($expectedMessage->getMessageId(), $actualMessage->getMessageId(), 'getMessageId'); $this->assertEquals($expectedMessage->getMessageLocation(), $actualMessage->getMessageLocation(), 'getMessageLocation'); $this->assertEquals($expectedMessage->getReplyTo(), $actualMessage->getReplyTo(), 'getReplyTo'); $this->assertEquals($expectedMessage->getReplyToSessionId(), $actualMessage->getReplyToSessionId(), 'getReplyToSessionId'); $this->assertEquals($expectedMessage->getScheduledEnqueueTimeUtc(), $actualMessage->getScheduledEnqueueTimeUtc(), 'getScheduledEnqueueTimeUtc'); // Note: The SequenceNumber property is controlled by the server, so cannot compare it. $this->assertTrue(is_int($actualMessage->getSequenceNumber()), 'is_int($actualMessage->getSequenceNumber)'); $this->assertEquals($expectedMessage->getSessionId(), $actualMessage->getSessionId(), 'getSessionId'); $this->assertEquals($expectedMessage->getTo(), $actualMessage->getTo(), 'getTo'); // Note: The BrokerProperties does not need to be tested, as most of // the BrokerMessage properties call into it. if (is_null($customProperties)) { $expectedProperties = $expectedMessage->getProperties(); $index = Utilities::tryGetValue($expectedProperties, 'i', 1); $customProperties = $this->getCustomProperties(intval($index)); } $actualProperties = $actualMessage->getProperties(); $this->assertEquals(count($customProperties), count($actualProperties), 'count(getProperties)'); foreach ($customProperties as $key => $value) { // Guids from the server cannot be known in advance if ($value != 'GUID') { $this->assertEquals($value, $actualProperties[strtolower($key)], 'getProperties[\'' . $key . '\']'); } } }
/** * Gets header value. * * @param string $name The header name. * * @return mix */ public function getHeader($name) { return Utilities::tryGetValue($this->_headers, $name); }