public function createContainer($containerName, $options = null)
 {
     if (is_null($options)) {
         $options = new CreateContainerOptions();
         $options->setPublicAccess('container');
     }
     $this->restProxy->createContainer($containerName, $options);
     $this->_createdContainers[] = $containerName;
 }
Пример #2
0
function createContainerSample($blobClient)
{
    // OPTIONAL: Set public access policy and metadata.
    // Create container options object.
    $createContainerOptions = new CreateContainerOptions();
    // Set public access policy. Possible values are
    // PublicAccessType::CONTAINER_AND_BLOBS and PublicAccessType::BLOBS_ONLY.
    // CONTAINER_AND_BLOBS: full public read access for container and blob data.
    // BLOBS_ONLY: public read access for blobs. Container data not available.
    // If this value is not specified, container data is private to the account owner.
    $createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);
    // Set container metadata
    $createContainerOptions->addMetaData("key1", "value1");
    $createContainerOptions->addMetaData("key2", "value2");
    try {
        // Create container.
        $blobClient->createContainer("mycontainer", $createContainerOptions);
    } catch (ServiceException $e) {
        $code = $e->getCode();
        $error_message = $e->getMessage();
        echo $code . ": " . $error_message . PHP_EOL;
    }
}
 /**
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createContainer
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::deleteContainer
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getContainerMetadata
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::listContainers
  */
 private function createContainerWorker($options)
 {
     $container = BlobServiceFunctionalTestData::getInterestingContainerName();
     $created = false;
     try {
         if (is_null($options)) {
             $this->restProxy->createContainer($container);
         } else {
             $this->restProxy->createContainer($container, $options);
         }
         $created = true;
         if (is_null($options)) {
             $options = new CreateContainerOptions();
         }
         if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
             $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
         }
         // Now check that the $container was $created correctly.
         // Make sure that the list of all applicable containers is correctly updated.
         $opts = new ListContainersOptions();
         $opts->setPrefix(BlobServiceFunctionalTestData::$testUniqueId);
         $qs = $this->restProxy->listContainers($opts);
         $this->assertEquals(count($qs->getContainers()), count(BlobServiceFunctionalTestData::$testContainerNames) + 1, 'After adding one, with Prefix=(\'' . BlobServiceFunctionalTestData::$testUniqueId . '\'), then Containers length');
         // Check the metadata on the container
         $ret = $this->restProxy->getContainerMetadata($container);
         $this->verifyCreateContainerWorker($ret, $options);
         $this->restProxy->deleteContainer($container);
     } catch (ServiceException $e) {
         if (is_null($options)) {
             $options = new CreateContainerOptions();
         }
         if (is_null($options->getTimeout()) || $options->getTimeout() >= 1) {
             throw $e;
         } else {
             $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
         }
     }
     if ($created) {
         try {
             $this->restProxy->deleteContainer($container);
         } catch (ServiceException $e) {
             // Ignore.
         }
     }
 }
 public static function getInterestingCreateContainerOptions()
 {
     $ret = array();
     $options = new CreateContainerOptions();
     array_push($ret, $options);
     $options = new CreateContainerOptions();
     $options->setTimeout(10);
     array_push($ret, $options);
     $options = new CreateContainerOptions();
     $options->setTimeout(-10);
     array_push($ret, $options);
     $options = new CreateContainerOptions();
     $options->setPublicAccess('container');
     array_push($ret, $options);
     $options = new CreateContainerOptions();
     $options->setPublicAccess('blob');
     array_push($ret, $options);
     $options = new CreateContainerOptions();
     $metadata = array('foo' => 'bar', 'boo' => 'baz');
     $options->setMetadata($metadata);
     array_push($ret, $options);
     return $ret;
 }
 /**
  * @return void
  */
 protected function createContainer()
 {
     $createContainerOptions = new CreateContainerOptions();
     $createContainerOptions->setPublicAccess(PublicAccessType::BLOBS_ONLY);
     try {
         $this->blobRestProxy->createContainer($this->container, $createContainerOptions);
     } catch (ServiceException $e) {
         // Code 409 - "container already exists" is ok in this case
         if (!($e->getCode() === 409)) {
             $flashMessage = $this->getFlashMessage($e);
             $this->getMessageQueueByIdentifier()->enqueue($flashMessage);
         }
     }
 }
 /**
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createContainer
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::deleteContainer
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getContainerACL
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getContainerMetadata
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getContainerProperties
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::listContainers
  */
 public function testCreateContainerWithMetadataWorks()
 {
     // Act
     $opts = new CreateContainerOptions();
     $opts->setPublicAccess('blob');
     $opts->addMetadata('test', 'bar');
     $opts->addMetadata('blah', 'bleah');
     $this->restProxy->createContainer(self::$_creatable_container_2, $opts);
     $prop = $this->restProxy->getContainerMetadata(self::$_creatable_container_2);
     $prop2 = $this->restProxy->getContainerProperties(self::$_creatable_container_2);
     $acl = $this->restProxy->getContainerACL(self::$_creatable_container_2)->getContainerACL();
     $opts = new ListContainersOptions();
     $opts->setPrefix(self::$_creatable_container_2);
     $opts->setIncludeMetadata(true);
     $results2 = $this->restProxy->listContainers($opts);
     $this->restProxy->deleteContainer(self::$_creatable_container_2);
     // Assert
     $this->assertNotNull($prop, '$prop');
     $this->assertNotNull($prop->getETag(), '$prop->getETag()');
     $this->assertNotNull($prop->getLastModified(), '$prop->getLastModified()');
     $this->assertNotNull($prop->getMetadata(), '$prop->getMetadata()');
     $this->assertEquals(2, count($prop->getMetadata()), 'count($prop->getMetadata())');
     $this->assertTrue(Utilities::arrayKeyExistsInsensitive('test', $prop->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'test\', $prop->getMetadata())');
     $this->assertTrue(!(array_search('bar', $prop->getMetadata()) === FALSE), '!(array_search(\'bar\', $prop->getMetadata()) === FALSE)');
     $this->assertTrue(Utilities::arrayKeyExistsInsensitive('blah', $prop->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'blah\', $prop->getMetadata())');
     $this->assertTrue(!(array_search('bleah', $prop->getMetadata()) === FALSE), '!(array_search(\'bleah\', $prop->getMetadata()) === FALSE)');
     $this->assertNotNull($prop2, '$prop2');
     $this->assertNotNull($prop2->getETag(), '$prop2->getETag()');
     $this->assertNotNull($prop2->getLastModified(), '$prop2->getLastModified()');
     $this->assertNotNull($prop2->getMetadata(), '$prop2->getMetadata()');
     $this->assertEquals(2, count($prop2->getMetadata()), 'count($prop2->getMetadata())');
     $this->assertTrue(Utilities::arrayKeyExistsInsensitive('test', $prop2->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'test\', $prop2->getMetadata())');
     $this->assertTrue(!(array_search('bar', $prop2->getMetadata()) === FALSE), '!(array_search(\'bar\', $prop2->getMetadata()) === FALSE)');
     $this->assertTrue(Utilities::arrayKeyExistsInsensitive('blah', $prop2->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'blah\', $prop2->getMetadata())');
     $this->assertTrue(!(array_search('bleah', $prop2->getMetadata()) === FALSE), '!(array_search(\'bleah\', $prop2->getMetadata()) === FALSE)');
     $this->assertNotNull($results2, '$results2');
     $this->assertEquals(1, count($results2->getContainers()), 'count($results2->getContainers())');
     $container0 = $results2->getContainers();
     $container0 = $container0[0];
     // The capitalizaion gets changed.
     $this->assertTrue(Utilities::arrayKeyExistsInsensitive('test', $container0->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'test\', $container0->getMetadata())');
     $this->assertTrue(!(array_search('bar', $container0->getMetadata()) === FALSE), '!(array_search(\'bar\', $container0->getMetadata()) === FALSE)');
     $this->assertTrue(Utilities::arrayKeyExistsInsensitive('blah', $container0->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'blah\', $container0->getMetadata())');
     $this->assertTrue(!(array_search('bleah', $container0->getMetadata()) === FALSE), '!(array_search(\'bleah\', $container0->getMetadata()) === FALSE)');
     $this->assertNotNull($acl, '$acl');
 }
Пример #7
0
 /**
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getContainerMetadata
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::_getContainerPropertiesImpl
  */
 public function testGetContainerMetadata()
 {
     // Setup
     $name = 'getcontainermetadata' . $this->createSuffix();
     $options = new CreateContainerOptions();
     $expected = array('name1' => 'MyName1', 'mymetaname' => '12345', 'values' => 'Microsoft_');
     $options->setMetadata($expected);
     $this->createContainer($name, $options);
     $result = $this->restProxy->getContainerProperties($name);
     $expectedETag = $result->getETag();
     $expectedLastModified = $result->getLastModified();
     // Test
     $result = $this->restProxy->getContainerMetadata($name);
     // Assert
     $this->assertEquals($expectedETag, $result->getETag());
     $this->assertEquals($expectedLastModified, $result->getLastModified());
     $this->assertEquals($expected, $result->getMetadata());
 }
 /**
  * @covers MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions::addMetadata
  */
 public function testAddMetadata()
 {
     // Setup
     $container = new CreateContainerOptions();
     $key = 'key1';
     $value = 'value1';
     $expected = array($key => $value);
     // Test
     $container->addMetadata($key, $value);
     // Assert
     $this->assertEquals($expected, $container->getMetadata());
 }
Пример #9
0
 /**
  * Creates a new container in the given storage account.
  * 
  * @param string                        $container The container name.
  * @param Models\CreateContainerOptions $options   The optional parameters.
  * 
  * @return none
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179468.aspx
  */
 public function createContainer($container, $options = null)
 {
     Validate::isString($container, 'container');
     Validate::notNullOrEmpty($container, 'container');
     $method = Resources::HTTP_PUT;
     $headers = array();
     $postParams = array();
     $queryParams = array(Resources::QP_REST_TYPE => 'container');
     $path = $container;
     $statusCode = Resources::STATUS_CREATED;
     if (is_null($options)) {
         $options = new CreateContainerOptions();
     }
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $metadata = $options->getMetadata();
     $headers = $this->generateMetadataHeaders($metadata);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_PUBLIC_ACCESS, $options->getPublicAccess());
     $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode);
 }