/** * 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; }
/** * @covers MicrosoftAzure\Storage\Blob\Models\ListBlobBlocksResult::setCommittedBlocks * @covers MicrosoftAzure\Storage\Blob\Models\ListBlobBlocksResult::getCommittedBlocks */ public function testSetCommittedBlocks() { // Setup $result = new ListBlobBlocksResult(); $expected = array('Block1' => 10, 'Block2' => 20, 'Block3' => 30); // Test $result->setCommittedBlocks($expected); // Assert $this->assertEquals($expected, $result->getCommittedBlocks()); }
/** * Retrieves the list of blocks that have been uploaded as part of a block blob. * * There are two block lists maintained for a blob: * 1) Committed Block List: The list of blocks that have been successfully * committed to a given blob with commitBlobBlocks. * 2) Uncommitted Block List: The list of blocks that have been uploaded for a * blob using Put Block (REST API), but that have not yet been committed. * These blocks are stored in Windows Azure in association with a blob, but do * not yet form part of the blob. * * @param string $container name of the container * @param string $blob name of the blob * @param Models\ListBlobBlocksOptions $options optional parameters * * @return Models\ListBlobBlocksResult * * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179400.aspx */ public function listBlobBlocks($container, $blob, $options = null) { Validate::isString($container, 'container'); Validate::isString($blob, 'blob'); Validate::notNullOrEmpty($blob, 'blob'); $method = Resources::HTTP_GET; $headers = array(); $postParams = array(); $queryParams = array(); $path = $this->_createPath($container, $blob); $statusCode = Resources::STATUS_OK; if (is_null($options)) { $options = new ListBlobBlocksOptions(); } $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId()); $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout()); $this->addOptionalQueryParam($queryParams, Resources::QP_BLOCK_LIST_TYPE, $options->getBlockListType()); $this->addOptionalQueryParam($queryParams, Resources::QP_SNAPSHOT, $options->getSnapshot()); $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'blocklist'); $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode); $parsed = $this->dataSerializer->unserialize($response->getBody()); return ListBlobBlocksResult::create(HttpFormatter::formatHeaders($response->getHeaders()), $parsed); }