/** * Creates new QueryTablesResult object * * @param array $headers The HTTP response headers * @param array $entries The table entriess * * @return \MicrosoftAzure\Storage\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 \MicrosoftAzure\Storage\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; }
/** * @covers MicrosoftAzure\Storage\Common\Internal\Utilities::tryGetValue */ public function testTryGetValueWithNull() { // Setup $key = 10; $data = array(10, 20, 30); // Test $actual = Utilities::tryGetValue($data, $key); $this->assertNull($actual); }
/** * 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 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 BatchError object. * * @param MicrosoftAzure\Storage\Common\ServiceException $error The error object. * @param array $headers The response headers. * * @return \MicrosoftAzure\Storage\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 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; }
/** * Creates ListQueuesResult object from parsed XML response. * * @param array $parsedResponse XML response parsed into array. * * @return MicrosoftAzure\Storage\Queue\Models\ListQueuesResult. */ public static function create($parsedResponse) { $result = new ListQueuesResult(); $serviceEndpoint = Utilities::tryGetKeysChainValue($parsedResponse, Resources::XTAG_ATTRIBUTES, Resources::XTAG_SERVICE_ENDPOINT); $result->_accountName = Utilities::tryParseAccountNameFromUrl($serviceEndpoint); $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'], $serviceEndpoint . $value['Name']); $metadata = Utilities::tryGetValue($value, Resources::QP_METADATA); $queue->setMetadata(is_null($metadata) ? array() : $metadata); $result->_queues[] = $queue; } return $result; }
/** * Gets property object from the entity properties. * * @param string $name The property name. * * @return Property */ public function getProperty($name) { return Utilities::tryGetValue($this->_properties, $name); }
/** * Serializes given array. The array indices must be string to use them as * as element name. * * @param array $array The object to serialize represented in array. * @param array $properties The used properties in the serialization process. * * @return string */ public function serialize($array, $properties = null) { $xmlVersion = '1.0'; $xmlEncoding = 'UTF-8'; $standalone = Utilities::tryGetValue($properties, self::STANDALONE); $defaultTag = Utilities::tryGetValue($properties, self::DEFAULT_TAG); $rootName = Utilities::tryGetValue($properties, self::ROOT_NAME); $docNamespace = Utilities::tryGetValue($array, Resources::XTAG_NAMESPACE, null); if (!is_array($array)) { return false; } $xmlw = new \XmlWriter(); $xmlw->openMemory(); $xmlw->setIndent(true); $xmlw->startDocument($xmlVersion, $xmlEncoding, $standalone); if (is_null($docNamespace)) { $xmlw->startElement($rootName); } else { foreach ($docNamespace as $uri => $prefix) { $xmlw->startElementNS($prefix, $rootName, $uri); break; } } unset($array[Resources::XTAG_NAMESPACE]); self::_arr2xml($xmlw, $array, $defaultTag); $xmlw->endElement(); return $xmlw->outputMemory(true); }
/** * Creates BreakLeaseResult from response headers * * @param array $headers response headers * * @return BreakLeaseResult */ public static function create($headers) { $result = new BreakLeaseResult(); $result->setLeaseTime(Utilities::tryGetValue($headers, Resources::X_MS_LEASE_TIME)); return $result; }
private function verifygetEntityWorker($ent, $entReturned) { $expectedProps = array(); foreach ($ent->getProperties() as $pname => $actualProp) { if (is_null($actualProp) || !is_null($actualProp->getValue())) { $cloneProp = null; if (!is_null($actualProp)) { $cloneProp = new Property(); $cloneProp->setEdmType($actualProp->getEdmType()); $cloneProp->setValue($actualProp->getValue()); } $expectedProps[$pname] = $cloneProp; } } // Compare the entities to make sure they match. $this->assertEquals($ent->getPartitionKey(), $entReturned->getPartitionKey(), 'getPartitionKey'); $this->assertEquals($ent->getRowKey(), $entReturned->getRowKey(), 'getRowKey'); $this->assertNotNull($entReturned->getETag(), 'getETag'); if (!is_null($ent->getETag())) { $this->assertEquals($ent->getETag(), $entReturned->getETag(), 'getETag'); } $this->assertNotNull($entReturned->getTimestamp(), 'getTimestamp'); if (is_null($ent->getTimestamp())) { // This property will come back, so need to account for it. $expectedProps['Timestamp'] = null; } else { $this->assertEquals($ent->getTimestamp(), $entReturned->getTimestamp(), 'getTimestamp'); } $this->assertNotNull($ent->getProperties(), 'getProperties'); $nullCount = 0; foreach ($entReturned->getProperties() as $pname => $actualProp) { if (is_null($actualProp->getValue())) { $nullCount++; } } // Need to skip null values from the count. $this->assertEquals(count($expectedProps) + $nullCount, count($entReturned->getProperties()), 'getProperties()'); foreach ($entReturned->getProperties() as $pname => $actualProp) { $this->println($actualProp->getEdmType() . ':' . (is_null($actualProp->getValue()) ? 'NULL' : ($actualProp->getValue() instanceof \DateTime ? "date" : $actualProp->getValue()))); } foreach ($entReturned->getProperties() as $pname => $actualProp) { $expectedProp = Utilities::tryGetValue($expectedProps, $pname, null); $this->assertNotNull($actualProp, 'getProperties[\'' . $pname . '\']'); if (!is_null($expectedProp)) { $this->compareProperties($pname, $actualProp, $expectedProp); } $this->assertEquals($entReturned->getProperty($pname), $actualProp, 'getProperty(\'' . $pname . '\')'); $this->assertEquals($entReturned->getPropertyValue($pname), $actualProp->getValue(), 'getPropertyValue(\'' . $pname . '\')'); } }
/** * Creates AcquireLeaseResult from response headers * * @param array $headers response headers * * @return AcquireLeaseResult */ public static function create($headers) { $result = new AcquireLeaseResult(); $result->setLeaseId(Utilities::tryGetValue($headers, Resources::X_MS_LEASE_ID)); return $result; }
/** * Compares between two responses by Content-ID header. * * @param \HTTP_Request2_Response $r1 The first response object. * @param \HTTP_Request2_Response $r2 The second response object. * * @return boolean */ private static function _compareUsingContentId($r1, $r2) { $h1 = array_change_key_case($r1->headers); $h2 = array_change_key_case($r2->headers); $c1 = Utilities::tryGetValue($h1, Resources::CONTENT_ID, 0); $c2 = Utilities::tryGetValue($h2, Resources::CONTENT_ID, 0); return intval($c1) >= intval($c2); }
/** * Gets the access control list (ACL) and any container-level access policies * for the container. * * @param string $container The container name. * @param Models\BlobServiceOptions $options The optional parameters. * * @return Models\GetContainerAclResult * * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179469.aspx */ public function getContainerAcl($container, $options = null) { Validate::isString($container, 'container'); $method = Resources::HTTP_GET; $headers = array(); $postParams = array(); $queryParams = array(); $path = $container; $statusCode = Resources::STATUS_OK; if (is_null($options)) { $options = new BlobServiceOptions(); } $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout()); $this->addOptionalQueryParam($queryParams, Resources::QP_REST_TYPE, 'container'); $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'acl'); $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode); $responseHeaders = HttpFormatter::formatHeaders($response->getHeaders()); $access = Utilities::tryGetValue($responseHeaders, Resources::X_MS_BLOB_PUBLIC_ACCESS); $etag = Utilities::tryGetValue($responseHeaders, Resources::ETAG); $modified = Utilities::tryGetValue($responseHeaders, Resources::LAST_MODIFIED); $modifiedDate = Utilities::convertToDateTime($modified); $parsed = $this->dataSerializer->unserialize($response->getBody()); return GetContainerAclResult::create($access, $etag, $modifiedDate, $parsed); }
/** * Updates the visibility timeout of a message and/or the message contents. * * @param string $queueName The queue name. * @param string $messageId The id of the message. * @param string $popReceipt The valid pop receipt * value returned from an earlier call to the Get Messages or Update Message * operation. * @param string $messageText The message contents. * @param int $visibilityTimeoutInSeconds Specifies the new * visibility timeout value, in seconds, relative to server time. * The new value must be larger than or equal to 0, and cannot be larger * than 7 days. The visibility timeout of a message cannot be set to a value * later than the expiry time. A message can be updated until it has been * deleted or has expired. * @param QueueServiceOptions $options The optional * parameters. * * @return MicrosoftAzure\Storage\Common\Models\UpdateMessageResult */ public function updateMessage($queueName, $messageId, $popReceipt, $messageText, $visibilityTimeoutInSeconds, $options = null) { Validate::isString($queueName, 'queueName'); Validate::notNullOrEmpty($queueName, 'queueName'); Validate::isString($messageId, 'messageId'); Validate::notNullOrEmpty($messageId, 'messageId'); Validate::isString($popReceipt, 'popReceipt'); Validate::notNullOrEmpty($popReceipt, 'popReceipt'); Validate::isString($messageText, 'messageText'); Validate::isInteger($visibilityTimeoutInSeconds, 'visibilityTimeoutInSeconds'); Validate::notNull($visibilityTimeoutInSeconds, 'visibilityTimeoutInSeconds'); $method = Resources::HTTP_PUT; $headers = array(); $postParams = array(); $queryParams = array(); $path = $queueName . '/messages' . '/' . $messageId; $body = Resources::EMPTY_STRING; $statusCode = Resources::STATUS_NO_CONTENT; if (is_null($options)) { $options = new QueueServiceOptions(); } $this->addOptionalQueryParam($queryParams, Resources::QP_VISIBILITY_TIMEOUT, $visibilityTimeoutInSeconds); $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout()); $this->addOptionalQueryParam($queryParams, Resources::QP_POPRECEIPT, $popReceipt); if (!empty($messageText)) { $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, Resources::URL_ENCODED_CONTENT_TYPE); $message = new QueueMessage(); $message->setMessageText($messageText); $body = $message->toXml($this->dataSerializer); } $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode, $body); $responseHeaders = HttpFormatter::formatHeaders($response->getHeaders()); $popReceipt = Utilities::tryGetValue($responseHeaders, Resources::X_MS_POPRECEIPT); $timeNextVisible = Utilities::tryGetValue($responseHeaders, Resources::X_MS_TIME_NEXT_VISIBLE); $date = Utilities::rfc1123ToDateTime($timeNextVisible); $result = new UpdateMessageResult(); $result->setPopReceipt($popReceipt); $result->setTimeNextVisible($date); return $result; }
/** * 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(); $serviceEndpoint = Utilities::tryGetKeysChainValue($parsed, Resources::XTAG_ATTRIBUTES, Resources::XTAG_SERVICE_ENDPOINT); $containerName = Utilities::tryGetKeysChainValue($parsed, Resources::XTAG_ATTRIBUTES, Resources::XTAG_CONTAINER_NAME); $result->_containerName = $containerName; $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($serviceEndpoint . $containerName . '/' . $value['Name']); $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(); $serviceEndpoint = Utilities::tryGetKeysChainValue($parsedResponse, Resources::XTAG_ATTRIBUTES, Resources::XTAG_SERVICE_ENDPOINT); $result->_accountName = Utilities::tryParseAccountNameFromUrl($serviceEndpoint); $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($serviceEndpoint . $value['Name']); $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; }
/** * Gets parameter value and if the name doesn't exist, return null. * * @param string $name The parameter name. * * @return mix */ public function getParameter($name) { return Utilities::tryGetValue($this->_params, $name); }
/** * Creates BlobProperties object from $parsed response in array representation * * @param array $parsed parsed response in array format. * * @return BlobProperties */ public static function create($parsed) { $result = new BlobProperties(); $clean = array_change_key_case($parsed); $date = Utilities::tryGetValue($clean, Resources::LAST_MODIFIED); $result->setBlobType(Utilities::tryGetValue($clean, 'blobtype')); $result->setContentLength(intval($clean[Resources::CONTENT_LENGTH])); $result->setETag(Utilities::tryGetValue($clean, Resources::ETAG)); if (!is_null($date)) { $date = Utilities::rfc1123ToDateTime($date); $result->setLastModified($date); } $result->setLeaseStatus(Utilities::tryGetValue($clean, 'leasestatus')); $result->setLeaseStatus(Utilities::tryGetValue($clean, Resources::X_MS_LEASE_STATUS, $result->getLeaseStatus())); $result->setSequenceNumber(intval(Utilities::tryGetValue($clean, Resources::X_MS_BLOB_SEQUENCE_NUMBER))); $result->setContentRange(Utilities::tryGetValue($clean, Resources::CONTENT_RANGE)); $result->setCacheControl(Utilities::tryGetValue($clean, Resources::CACHE_CONTROL)); $result->setBlobType(Utilities::tryGetValue($clean, Resources::X_MS_BLOB_TYPE, $result->getBlobType())); $result->setContentEncoding(Utilities::tryGetValue($clean, Resources::CONTENT_ENCODING)); $result->setContentLanguage(Utilities::tryGetValue($clean, Resources::CONTENT_LANGUAGE)); $result->setContentMD5(Utilities::tryGetValue($clean, Resources::CONTENT_MD5)); $result->setContentType(Utilities::tryGetValue($clean, Resources::CONTENT_TYPE)); return $result; }
/** * Creates ListBlobBlocksResult from given response headers and parsed body * * @param array $headers HTTP response headers * @param array $parsed HTTP response body in array representation * * @return ListBlobBlocksResult */ public static function create($headers, $parsed) { $result = new ListBlobBlocksResult(); $clean = array_change_key_case($headers); $result->setETag(Utilities::tryGetValue($clean, Resources::ETAG)); $date = Utilities::tryGetValue($clean, Resources::LAST_MODIFIED); if (!is_null($date)) { $date = Utilities::rfc1123ToDateTime($date); $result->setLastModified($date); } $result->setContentLength(intval(Utilities::tryGetValue($clean, Resources::X_MS_BLOB_CONTENT_LENGTH))); $result->setContentType(Utilities::tryGetValue($clean, Resources::CONTENT_TYPE)); $result->_uncommittedBlocks = self::_getEntries($parsed, 'UncommittedBlocks'); $result->_committedBlocks = self::_getEntries($parsed, 'CommittedBlocks'); return $result; }
/** * Unregisters a connection string source. * * @param string $name The source name. * * @return callable */ public static function unregisterSource($name) { Validate::isString($name, 'name'); Validate::notNullOrEmpty($name, 'name'); self::_init(); $sourceCallback = Utilities::tryGetValue(self::$_sources, $name); if (!is_null($sourceCallback)) { unset(self::$_sources[$name]); } return $sourceCallback; }
/** * Gets header value. * * @param string $name The header name. * * @return mix */ public function getHeader($name) { return Utilities::tryGetValue($this->_headers, $name); }