Esempio n. 1
0
 /**
  * Creates block list from array of blocks.
  * 
  * @param array $array The blocks array.
  * 
  * @return BlockList
  */
 public static function create($array)
 {
     $blockList = new BlockList();
     foreach ($array as $value) {
         $blockList->addEntry($value->getBlockId(), $value->getType());
     }
     return $blockList;
 }
Esempio n. 2
0
 /**
  * @covers MicrosoftAzure\Storage\Blob\Models\BlockList::toXml
  */
 public function testToXml()
 {
     // Setup
     $blockList = new BlockList();
     $blockList->addLatestEntry(base64_encode('1234'));
     $blockList->addCommittedEntry(base64_encode('1239'));
     $blockList->addLatestEntry(base64_encode('1236'));
     $blockList->addCommittedEntry(base64_encode('1237'));
     $blockList->addUncommittedEntry(base64_encode('1238'));
     $blockList->addLatestEntry(base64_encode('1235'));
     $blockList->addUncommittedEntry(base64_encode('1240'));
     $expected = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<BlockList>' . "\n" . ' <Latest>MTIzNA==</Latest>' . "\n" . ' <Committed>MTIzOQ==</Committed>' . "\n" . ' <Latest>MTIzNg==</Latest>' . "\n" . ' <Committed>MTIzNw==</Committed>' . "\n" . ' <Uncommitted>MTIzOA==</Uncommitted>' . "\n" . ' <Latest>MTIzNQ==</Latest>' . "\n" . ' <Uncommitted>MTI0MA==</Uncommitted>' . "\n" . '</BlockList>' . "\n";
     // Test
     $actual = $blockList->toXml(new XmlSerializer());
     // Assert
     $this->assertEquals($expected, $actual);
 }
 /**
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::commitBlobBlocks
  * @covers MicrosoftAzure\Storage\Blob\Models\BlockList::toXml
  */
 public function testCommitBlobBlocks()
 {
     // Setup
     $name = 'commitblobblocks' . $this->createSuffix();
     $blob = 'myblob';
     $id1 = 'AAAAAA==';
     $id2 = 'ANAAAA==';
     $this->createContainer($name);
     $this->restProxy->createBlobBlock($name, $blob, $id1, 'Hello world');
     $this->restProxy->createBlobBlock($name, $blob, $id2, 'Hello world');
     $blockList = new BlockList();
     $blockList->addEntry($id1, BlobBlockType::LATEST_TYPE);
     $blockList->addEntry($id2, BlobBlockType::LATEST_TYPE);
     // Test
     $this->restProxy->commitBlobBlocks($name, $blob, $blockList);
     // Assert
     $result = $this->restProxy->listBlobs($name);
     $this->assertCount(1, $result->getBlobs());
 }
 /**
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::commitBlobBlocks
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlobBlock
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlockBlob
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::listBlobBlocks
  */
 public function testCommitBlobBlocksWorks()
 {
     // Act
     $container = self::$_test_container_for_blobs;
     $blob = 'test14';
     $blockId1 = base64_encode('1fedcba');
     $blockId2 = base64_encode('2abcdef');
     $blockId3 = base64_encode('3zzzzzz');
     $this->restProxy->createBlockBlob($container, $blob, '');
     $this->restProxy->createBlobBlock($container, $blob, $blockId1, str_pad('', 256));
     $this->restProxy->createBlobBlock($container, $blob, $blockId2, str_pad('', 512));
     $this->restProxy->createBlobBlock($container, $blob, $blockId3, str_pad('', 195));
     $blockList = new BlockList();
     $blockList->addUncommittedEntry($blockId1);
     $blockList->addLatestEntry($blockId3);
     $this->restProxy->commitBlobBlocks($container, $blob, $blockList);
     $opts = new ListBlobBlocksOptions();
     $opts->setIncludeCommittedBlobs(true);
     $opts->setIncludeUncommittedBlobs(true);
     $result = $this->restProxy->listBlobBlocks($container, $blob, $opts);
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertNotNull($result->getLastModified(), '$result->getLastModified()');
     $this->assertNotNull($result->getETag(), '$result->getETag()');
     $this->assertEquals(256 + 195, $result->getContentLength(), '$result->getContentLength()');
     $this->assertNotNull($result->getCommittedBlocks(), '$result->getCommittedBlocks()');
     $this->assertEquals(2, count($result->getCommittedBlocks()), 'count($result->getCommittedBlocks())');
     $comblk = $result->getCommittedBlocks();
     $keys = array_keys($comblk);
     $this->assertEquals($blockId1, $keys[0], '$keys[0]');
     $this->assertEquals(256, $comblk[$keys[0]], '$comblk[$keys[0]]');
     $this->assertEquals($blockId3, $keys[1], '$keys[1]');
     $this->assertEquals(195, $comblk[$keys[1]], '$comblk[$keys[1]]');
     $this->assertNotNull($result->getUncommittedBlocks(), '$result->getUncommittedBlocks()');
     $this->assertEquals(0, count($result->getUncommittedBlocks()), 'count($result->getUncommittedBlocks())');
 }
Esempio n. 5
0
 /**
  * This method writes a blob by specifying the list of block IDs that make up the
  * blob. In order to be written as part of a blob, a block must have been 
  * successfully written to the server in a prior createBlobBlock method.
  * 
  * You can call Put Block List to update a blob by uploading only those blocks 
  * that have changed, then committing the new and existing blocks together. 
  * You can do this by specifying whether to commit a block from the committed 
  * block list or from the uncommitted block list, or to commit the most recently
  * uploaded version of the block, whichever list it may belong to.
  * 
  * @param string                         $container The container name.
  * @param string                         $blob      The blob name.
  * @param Models\BlockList|array         $blockList The block entries.
  * @param Models\CommitBlobBlocksOptions $options   The optional parameters.
  * 
  * @return CopyBlobResult
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179467.aspx 
  */
 public function commitBlobBlocks($container, $blob, $blockList, $options = null)
 {
     Validate::isString($container, 'container');
     Validate::isString($blob, 'blob');
     Validate::notNullOrEmpty($blob, 'blob');
     Validate::isTrue($blockList instanceof BlockList || is_array($blockList), sprintf(Resources::INVALID_PARAM_MSG, 'blockList', get_class(new BlockList())));
     $method = Resources::HTTP_PUT;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $path = $this->_createPath($container, $blob);
     $statusCode = Resources::STATUS_CREATED;
     $isArray = is_array($blockList);
     $blockList = $isArray ? BlockList::create($blockList) : $blockList;
     $body = $blockList->toXml($this->dataSerializer);
     if (is_null($options)) {
         $options = new CommitBlobBlocksOptions();
     }
     $blobContentType = $options->getBlobContentType();
     $blobContentEncoding = $options->getBlobContentEncoding();
     $blobContentLanguage = $options->getBlobContentLanguage();
     $blobContentMD5 = $options->getBlobContentMD5();
     $blobCacheControl = $options->getBlobCacheControl();
     $leaseId = $options->getLeaseId();
     $contentType = Resources::URL_ENCODED_CONTENT_TYPE;
     $metadata = $options->getMetadata();
     $headers = $this->generateMetadataHeaders($metadata);
     $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition());
     $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $leaseId);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CACHE_CONTROL, $blobCacheControl);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CONTENT_TYPE, $blobContentType);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CONTENT_ENCODING, $blobContentEncoding);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CONTENT_LANGUAGE, $blobContentLanguage);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CONTENT_MD5, $blobContentMD5);
     $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, $contentType);
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'blocklist');
     return $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode, $body);
 }