File: Container.md

package info (click to toggle)
owncloud 7.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 104,192 kB
  • sloc: php: 403,584; xml: 5,843; perl: 630; cs: 504; sh: 453; sql: 271; python: 221; makefile: 104
file content (181 lines) | stat: -rw-r--r-- 5,200 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
## Setup

```php
use OpenCloud\Rackspace;

// Create a client object to communicate with various Rackspace Cloud services.
$client = new Rackspace(RACKSPACE_US, array(
    'username' => 'Replace this with your Rackspace Cloud user name',
    'apiKey' => 'Replace this with your Rackspace Cloud API key'
));

// Create a service object to use the object store service. The sample code
// creates the object store in the 'DFW' region.
$service = $client->objectStoreService('cloudFiles', 'DFW');
```

## Create container

To create a new container, you just need to define its name:

```php
$container = $service->createContainer('my_amazing_container');
```

If the response returned is `FALSE`, there was an API error - most likely due to the fact you have a naming collision.

Container names must be valid strings between 0 and 256 characters. Forward slashes are not currently permitted.


## List containers

### Return a list of containers

```php
$containerList = $service->listContainers();

while ($container = $containerList->next()) {
    // Do stuff; some examples below
    printf("Container name: %s\n", $container->name);
    printf("Number of objects within container: %d\n", $container->getObjectCount());
}
```

Container names are sorted based on a binary comparison, a single built-in collating sequence that compares string
data using SQLite's memcmp() function, regardless of text encoding.

The list is limited to 10,000 containers at a time. See 1.3 for ways to limit and navigate this list.

### Return a formatted list of containers

Currently, the SDK only supports JSON-formatted responses.

### Controlling a large list of containers

You may limit and control this list of results by using the `marker` and `end_marker` parameters. The former parameter
(`marker`) tells the API where to begin the list, and the latter (`end_marker`) tells it where to end the list. You may
use either of them independently or together. You may also use the `limit` parameter to fix the number of containers
returned.

To list a set of containers between two fixed points:

```php
$someContainers = $service->listContainers(array(
    'marker'     => 'container_55',
    'end_marker' => 'container_2001'
));
```

Or to return a limited set:

```php
$someContainers = $service->listContainers(array('limit' => 560));
```

## Get container

To retrieve a certain container, either to access its object or metadata:

```php
$container = $service->getContainer('container_name');

echo $container->getObjectCount();
echo $container->getBytesUsed();
```

## Delete container

Deleting a container is easy:
```php
$container->delete();
```

Please bear mind that you must delete all objects inside a container before deleting it. This is done for you if you
set the `$deleteObjects` parameter to `TRUE` like so:

```php
$container->delete(TRUE);
```

You can also do it manually:

```php
$container->deleteAllObjects();
$container->delete();
```

## Create or update container metadata

```php
$container->saveMetadata(array(
    'Author' => 'Virginia Woolf',
    'Published' => '1931'
));
```

Please bear in mind that this action will set metadata to this array - overriding existing values and wiping those left
out. To _append_ values to the current metadata:

```php
$metadata = $container->appendToMetadata(array(
    'Publisher' => 'Hogarth'
));
```

If you only want to set the metadata to the local object, and not immediately retain these values on the API, you can
use a standard setter method - which can contribute to eventual actions like an update:

```php
$container->setMetadata(array('Foo' => 'Bar'));
```

## Container quotas

The container_quotas middleware implements simple quotas that can be imposed on Cloud Files containers by a user.
Setting container quotas can be useful for limiting the scope of containers that are delegated to non-admin users,
exposed to formpost uploads, or just as a self-imposed sanity check.

To set quotas for a container:

```php
use OpenCloud\Common\Constants\Size;

$container->setCountQuota(1000);
$container->setBytesQuota(2.5 * Size::GB);
```

And to retrieve them:

```php
echo $container->getCountQuota();
echo $container->getBytesQuota();
```

## Access log delivery

To view your object access, turn on Access Log Delivery. You can use access logs to analyze the number of people who
access your objects, where they come from, how many requests for each object you receive, and time-based usage patterns
(such as monthly or seasonal usage).

```php
$container->enableLogging();
$container->disableLogging();
```

## Syncing containers

You can synchronize local directories with your CloudFiles/Swift containers very easily. When you do this, the container
will mirror exactly the nested file structure within your local directory:

```php
$container->uploadDirectory('/home/Jamie/blog');
```

There are four scenarios you should be aware of:

Local|Remote|Comparison|Action
---|---|---|---
File exists|File exists|Identical checksum|No action
File exists|File exists|Different checksum|Local file overwrites remote
File exists|File does not exist|-|Local file created in Swift
Files does not exist|File exists|-|Remote file deleted