Swift is OpenStack’s object storage service. In the php-opencloud library, it is accessed through the ObjectStore class (OpenStack or Rackspace) created by the connection object.
For example:
$cloud = new OpenCloudOpenStack(array(
'username'=>'{username}','password'=>'{password}'));
$swift = $cloud->ObjectStore('cloudFiles','DFW');
Using the newly created $swift, you can use different object storage components.
The highest-level object storage component instance is Container. Container is the collection name of objects, which is similar to directories and folders in the file system (not actually equivalent).
All objects are saved in Container.
List all Containers in an object storage instance
ContainerList object is a collection of Container objects. List all Containers in the object storage instance:
$containers = $swift->ContainerList();
while($container = $containers->Next())
printf("%sn", $container->name);
Like other object collections, this also supports First(), Next() and Size() methods.
Create a new Container
Create a new (empty) container using the Container() method of the newly created $swift object above.
$mycontainer = $swift->Container();
Save the Container to the object storage instance and use the Create() method:
$mycontainer->Create('MyContainerName');
name does not have to be in the Create() method if name has been set. It is also convenient to specify the name directly in the method.
$mycontainer->name = 'MyContainerName';
$mycontainer->Create();
Retrieve existing Container
If you pass a parameter to the Container() method of the ObjectStore object, you can retrieve an existing Container:
$oldcontainer = $swift->Container('SomeOldContainer');
In this case, information about SomeOldContainer will be retrieved. This contains the Container's metadata information.
printf("Container %s has %d object(s) consuming %d bytesn",
$oldcontainer->name, $oldcontainer->count, $oldcontainer->bytes);
Delete Container
Delete() method deletes Container
$oldcontainer->Delete();
Please note that the Container must be empty when it is deleted, that is, there must be no object associated with it.
Update Container
Under the hood, containers are created and updated exactly the same way. You can use the Create() method to update a Container; however, the Update() method is also used as an alias for the Create() method because the semantics may be different (in your program):
$oldcontainer->metadata->update_time = time();
$oldcontainer->Update();
http://www.bkjia.com/PHPjc/477123.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477123.htmlTechArticleSwift is OpenStack’s object storage service. In the php-opencloud library, it is accessed through the ObjectStore class (OpenStack or Rackspace) created by the connection object. For example: $cloud = new OpenClou...