/**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * Computes canonicalized headers for headers array.
  *
  * @param array $headers request headers.
  * 
  * @see Constructing the Canonicalized Headers String section at 
  *      http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx
  * 
  * @return array
  */
 protected function computeCanonicalizedHeaders($headers)
 {
     $canonicalizedHeaders = array();
     $normalizedHeaders = array();
     $validPrefix = Resources::X_MS_HEADER_PREFIX;
     if (is_null($normalizedHeaders)) {
         return $canonicalizedHeaders;
     }
     foreach ($headers as $header => $value) {
         // Convert header to lower case.
         $header = strtolower($header);
         // Retrieve all headers for the resource that begin with x-ms-,
         // including the x-ms-date header.
         if (Utilities::startsWith($header, $validPrefix)) {
             // Unfold the string by replacing any breaking white space
             // (meaning what splits the headers, which is \r\n) with a single
             // space.
             $value = str_replace("\r\n", ' ', $value);
             // Trim any white space around the colon in the header.
             $value = ltrim($value);
             $header = rtrim($header);
             $normalizedHeaders[$header] = $value;
         }
     }
     // Sort the headers lexicographically by header name, in ascending order.
     // Note that each header may appear only once in the string.
     ksort($normalizedHeaders);
     foreach ($normalizedHeaders as $key => $value) {
         $canonicalizedHeaders[] = $key . ':' . $value;
     }
     return $canonicalizedHeaders;
 }
 /**
  * Converts the current object into ordered array representation.
  * 
  * @return array
  */
 protected function toArray()
 {
     $arr = parent::toArray();
     $order = array(Resources::XTAG_NAMESPACE, Resources::XTAG_SERVICE_NAME, Resources::XTAG_LABEL, Resources::XTAG_DESCRIPTION, Resources::XTAG_LOCATION, Resources::XTAG_AFFINITY_GROUP);
     $ordered = Utilities::orderArray($arr, $order);
     return $ordered;
 }
 /**
  * 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;
 }
 /**
  * Given array of MIME parts in raw string, this function converts them into MIME
  * representation. 
  * 
  * @param array $bodyPartContents The MIME body parts.
  * 
  * @return array Returns array with two elements 'headers' and 'body' which
  * represents the MIME message.
  */
 public function encodeMimeMultipart($bodyPartContents)
 {
     $count = count($bodyPartContents);
     $mimeType = Resources::MULTIPART_MIXED_TYPE;
     $batchGuid = Utilities::getGuid();
     $batchId = sprintf('batch_%s', $batchGuid);
     $contentType1 = array('content_type' => "{$mimeType}");
     $changeSetGuid = Utilities::getGuid();
     $changeSetId = sprintf('changeset_%s', $changeSetGuid);
     $contentType2 = array('content_type' => "{$mimeType}; boundary={$changeSetId}");
     $options = array('encoding' => 'binary', 'content_type' => Resources::HTTP_TYPE);
     // Create changeset MIME part
     $changeSet = new \Mail_mimePart();
     for ($i = 0; $i < $count; $i++) {
         $changeSet->addSubpart($bodyPartContents[$i], $options);
     }
     // Encode the changeset MIME part
     $changeSetEncoded = $changeSet->encode($changeSetId);
     // Create the batch MIME part
     $batch = new \Mail_mimePart(Resources::EMPTY_STRING, $contentType1);
     // Add changeset encoded to batch MIME part
     $batch->addSubpart($changeSetEncoded['body'], $contentType2);
     // Encode batch MIME part
     $batchEncoded = $batch->encode($batchId);
     return $batchEncoded;
 }
 /**
  * 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 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;
 }
Exemplo n.º 8
0
 /**
  * Creates GetBlobResult from getBlob call.
  * 
  * @param array  $headers  The HTTP response headers.
  * @param string $body     The response body.
  * @param array  $metadata The blob metadata.
  * 
  * @return GetBlobResult
  */
 public static function create($headers, $body, $metadata)
 {
     $result = new GetBlobResult();
     $result->setContentStream(Utilities::stringToStream($body));
     $result->setProperties(BlobProperties::create($headers));
     $result->setMetadata(is_null($metadata) ? array() : $metadata);
     return $result;
 }
Exemplo n.º 9
0
 /**
  * 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;
 }
Exemplo n.º 10
0
 /**
  * Converts the current object into ordered array representation.
  * 
  * @return array
  */
 protected function toArray()
 {
     $arr = parent::toArray();
     $order = array(Resources::XTAG_NAMESPACE, Resources::XTAG_NAME, Resources::XTAG_LABEL, Resources::XTAG_DESCRIPTION, Resources::XTAG_LOCATION);
     Utilities::addIfNotEmpty(Resources::XTAG_NAME, $this->getName(), $arr);
     $ordered = Utilities::orderArray($arr, $order);
     return $ordered;
 }
Exemplo n.º 11
0
 /**
  * Creates CopyBlobResult object from the response of the copy blob request.
  * 
  * @param array $headers The HTTP response headers in array representation.
  * 
  * @return CopyBlobResult
  */
 public static function create($headers)
 {
     $result = new CopyBlobResult();
     $headerWithLowerCaseKey = array_change_key_case($headers);
     $result->setEtag($headerWithLowerCaseKey[Resources::ETAG]);
     $result->setLastModified(Utilities::rfc1123ToDateTime($headerWithLowerCaseKey[Resources::LAST_MODIFIED]));
     return $result;
 }
Exemplo n.º 12
0
 /**
  * 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;
 }
Exemplo n.º 13
0
 /**
  * Creates SetBlobMetadataResult from response headers.
  * 
  * @param array $headers response headers
  * 
  * @return SetBlobMetadataResult
  */
 public static function create($headers)
 {
     $result = new SetBlobMetadataResult();
     $date = $headers[Resources::LAST_MODIFIED];
     $result->setLastModified(Utilities::rfc1123ToDateTime($date));
     $result->setETag($headers[Resources::ETAG]);
     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();
     $rowStorageServices = Utilities::tryGetArray(Resources::XTAG_STORAGE_SERVICE, $parsed);
     foreach ($rowStorageServices as $rowStorageService) {
         $result->_storageServices[] = new StorageService($rowStorageService);
     }
     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;
 }
 /**
  * Creates GetBlobMetadataResult from response headers.
  * 
  * @param array $headers  The HTTP response headers.
  * @param array $metadata The blob metadata array.
  * 
  * @return GetBlobMetadataResult
  */
 public static function create($headers, $metadata)
 {
     $result = new GetBlobMetadataResult();
     $date = $headers[Resources::LAST_MODIFIED];
     $result->setLastModified(Utilities::rfc1123ToDateTime($date));
     $result->setEtag($headers[Resources::ETAG]);
     $result->setMetadata(is_null($metadata) ? array() : $metadata);
     return $result;
 }
Exemplo n.º 17
0
 /**
  * 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;
 }
Exemplo n.º 18
0
 /**
  * Creates CopyBlobResult object from the response of the copy blob request.
  * 
  * @param array $headers The HTTP response headers in array representation.
  * 
  * @return CopyBlobResult
  */
 public static function create($headers)
 {
     $result = new CopyBlobResult();
     $result->setETag(Utilities::tryGetValueInsensitive(Resources::ETAG, $headers));
     if (Utilities::arrayKeyExistsInsensitive(Resources::LAST_MODIFIED, $headers)) {
         $lastModified = Utilities::tryGetValueInsensitive(Resources::LAST_MODIFIED, $headers);
         $result->setLastModified(Utilities::rfc1123ToDateTime($lastModified));
     }
     return $result;
 }
 /**
  * Creates new ListAffinityGroupsResult from parsed response body.
  * 
  * @param array $parsed The parsed response body.
  * 
  * @return ListAffinityGroupsResult
  */
 public static function create($parsed)
 {
     $result = new self();
     $result->_affinityGroups = array();
     $entries = Utilities::tryGetArray(Resources::XTAG_AFFINITY_GROUP, $parsed);
     foreach ($entries as $value) {
         $result->_affinityGroups[] = new AffinityGroup($value);
     }
     return $result;
 }
 /**
  * @covers WindowsAzure\Blob\Models\CreateBlobPagesResult::setLastModified
  * @covers WindowsAzure\Blob\Models\CreateBlobPagesResult::getLastModified
  */
 public function testSetLastModified()
 {
     // Setup
     $expected = Utilities::rfc1123ToDateTime('Sun, 25 Sep 2011 19:42:18 GMT');
     $options = new CreateBlobPagesResult();
     $options->setLastModified($expected);
     // Test
     $options->setLastModified($expected);
     // Assert
     $this->assertEquals($expected, $options->getLastModified());
 }
 /**
  * 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;
 }
 /**
  * @covers WindowsAzure\Blob\Models\ListBlobBlocksResult::setLastModified
  * @covers WindowsAzure\Blob\Models\ListBlobBlocksResult::getLastModified
  */
 public function testSetLastModified()
 {
     // Setup
     $expected = Utilities::rfc1123ToDateTime('Sun, 25 Sep 2011 19:42:18 GMT');
     $result = new ListBlobBlocksResult();
     $result->setLastModified($expected);
     // Test
     $result->setLastModified($expected);
     // Assert
     $this->assertEquals($expected, $result->getLastModified());
 }
Exemplo n.º 23
0
 /**
  * @covers WindowsAzure\Blob\Models\BlobProperties::setLastModified
  * @covers WindowsAzure\Blob\Models\BlobProperties::getLastModified
  */
 public function testSetLastModified()
 {
     // Setup
     $expected = Utilities::rfc1123ToDateTime('Sun, 25 Sep 2011 19:42:18 GMT');
     $properties = new BlobProperties();
     $properties->setLastModified($expected);
     // Test
     $properties->setLastModified($expected);
     // Assert
     $this->assertEquals($expected, $properties->getLastModified());
 }
Exemplo n.º 24
0
 /**
  * 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;
 }
 /**
  * Serializes the current state.
  * 
  * @param CurrentState  $state        The current state.
  * @param IOutputStream $outputStream The output stream.
  * 
  * @return none
  */
 public function serialize($state, $outputStream)
 {
     $statusLeaseInfo = array('StatusLease' => array('@attributes' => array('ClientId' => $state->getClientId())));
     if ($state instanceof AcquireCurrentState) {
         $statusLeaseInfo['StatusLease']['Acquire'] = array('Incarnation' => $state->getIncarnation(), 'Status' => $state->getStatus(), 'Expiration' => Utilities::isoDate(date_timestamp_get($state->getExpiration())));
     } elseif ($state instanceof ReleaseCurrentState) {
         $statusLeaseInfo['StatusLease']['Release'] = array();
     }
     $currentState = Utilities::serialize($statusLeaseInfo, 'CurrentState');
     fwrite($outputStream, $currentState);
 }
 /**
  * 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 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 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 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;
 }
Exemplo n.º 30
0
 /**
  * Creates SetBlobPropertiesResult from response headers.
  * 
  * @param array $headers response headers
  * 
  * @return SetBlobPropertiesResult
  */
 public static function create($headers)
 {
     $result = new SetBlobPropertiesResult();
     $date = $headers[Resources::LAST_MODIFIED];
     $result->setLastModified(Utilities::rfc1123ToDateTime($date));
     $result->setETag($headers[Resources::ETAG]);
     if (array_key_exists(Resources::X_MS_BLOB_SEQUENCE_NUMBER, $headers)) {
         $sNumber = $headers[Resources::X_MS_BLOB_SEQUENCE_NUMBER];
         $result->setSequenceNumber(intval($sNumber));
     }
     return $result;
 }