HPCloud-PHP
1.2.0
PHP bindings for HPCloud and OpenStack services.
|
An object for ObjectStorage. More...
Public Member Functions | |
__construct ($name, $content=NULL, $type=NULL) | |
Construct a new object for storage. | |
setMetadata (array $array) | |
Set the metadata. | |
metadata () | |
Get any associated metadata. | |
setName ($name) | |
Override (change) the name of an object. | |
name () | |
Get the name. | |
setContentType ($type) | |
Set the content type (MIME type) for the object. | |
contentType () | |
Get the content type. | |
setContent ($content, $type=NULL) | |
Set the content for this object. | |
content () | |
Retrieve the content. | |
contentLength () | |
Calculate the content length. | |
eTag () | |
Generate an ETag for the ObjectStorage server. | |
setEncoding ($encoding) | |
Set the encoding for a file. | |
encoding () | |
Get the encoding (if any) for this object. | |
setDisposition ($disposition) | |
Set the content disposition. | |
disposition () | |
Get the current disposition string, if any. | |
setAdditionalHeaders ($headers) | |
Set additional headers for storage. | |
additionalHeaders () | |
Return additional headers. | |
removeHeaders ($keys) | |
Remove headers. | |
isChunked () | |
This object should be transmitted in chunks. |
Public Attributes | |
const | DEFAULT_CONTENT_TYPE = 'application/octet-stream' |
Protected Attributes | |
$name | |
The name of the object. | |
$content | |
The content. | |
$contentType = self::DEFAULT_CONTENT_TYPE | |
The content type. | |
$metadata = array() | |
Associative array of stored metadata. | |
$contentEncoding | |
$contentDisposition | |
$additionalHeaders = array() | |
Extension mechanism for new headers. |
An object for ObjectStorage.
The HPCloud ObjectStorage system provides a method for storing complete chunks of data (objects) in the cloud. This class describes such a chunk of data.
An object has the following basic components:
Objects are stored and retrieved by name. So it is assumed that, per container, no more than one file with a given name exists.
You may create Object instance and then store them in Containers. Likewise, a Container instance can retrieve Object instances from the remote object store.
Definition at line 55 of file Object.php.
__construct | ( | $name, | |
$content = NULL , |
|||
$type = NULL |
|||
) |
Construct a new object for storage.
string | $name | A name (may be pathlike) for the object. |
string | $content | Optional content to store in this object. This is the same as calling setContent(). |
string | $type | Optional content type for this content. This is the same as calling setContentType(). |
Definition at line 107 of file Object.php.
References $content, $name, Object\content(), Object\contentType(), and Object\name().
additionalHeaders | ( | ) |
Return additional headers.
Headers here have likely not been stored remotely until Container::save() is called on the object.
Definition at line 492 of file Object.php.
Referenced by Object\removeHeaders(), Container\save(), and Object\setAdditionalHeaders().
content | ( | ) |
Retrieve the content.
Retrieve the ENTIRE content of an object.
Note that this may be binary data (depending on what the original content is). PHP strings are generally binary safe, but use this with caution if you do not know what kind of data is stored in an object.
OpenStack does not do anything to validate that the content type is accurate. While contentType() is intended to provide useful information, poorly managed data can be written with the wrong content type.
When extending this class, you should make sure that this function returns the entire contents of an object.
string |
Reimplemented in RemoteObject.
Definition at line 315 of file Object.php.
References $content.
Referenced by Object\__construct(), Object\contentLength(), Object\eTag(), Container\save(), Object\setContent(), and Container\updateMetadata().
contentLength | ( | ) |
Calculate the content length.
This returns the number of bytes in a piece of content (not the number of characters). Among other things, it is used to let the remote object store know how big of an object to expect when transmitting data.
When extending this class, you should make sure to calculate the content length appropriately.
int |
Reimplemented in RemoteObject.
Definition at line 334 of file Object.php.
References Object\content().
Referenced by Container\save().
contentType | ( | ) |
Get the content type.
This returns the currently set content type.
string |
Definition at line 256 of file Object.php.
Referenced by Object\__construct(), Container\save(), Object\setContent(), Object\setContentType(), and Container\updateMetadata().
disposition | ( | ) |
Get the current disposition string, if any.
See setDisposition() for discussion.
string |
Definition at line 439 of file Object.php.
Referenced by Container\save().
encoding | ( | ) |
Get the encoding (if any) for this object.
Encoding is used to indicate how a file was encoded or compressed. See setEncoding() for more information.
string |
Definition at line 395 of file Object.php.
Referenced by Container\save().
eTag | ( | ) |
Generate an ETag for the ObjectStorage server.
OpenStack uses ETag to pass validation data. This generates an ETag using an MD5 hash of the content.
When extending this class, generate an ETag by creating an MD5 of the entire object's content (but not the metadata or name).
string |
Reimplemented in RemoteObject.
Definition at line 352 of file Object.php.
References Object\content().
Referenced by Container\save().
isChunked | ( | ) |
This object should be transmitted in chunks.
Indicates whether or not this object should be transmitted as chunked data (in HTTP).
This should be used when (a) the file size is large, or (b) the exact size of the file is unknown.
If this returns TRUE, it does not guarantee that the data will be transmitted in chunks. But it recommends that the underlying transport layer use chunked encoding.
The contentLength() method is not called for chunked transfers. So if this returns TRUE, contentLength() is ignored.
boolean |
Definition at line 544 of file Object.php.
Referenced by Container\save().
metadata | ( | ) |
Get any associated metadata.
This returns an associative array of all metadata for this object.
array |
Reimplemented in RemoteObject.
Definition at line 170 of file Object.php.
Referenced by Container\save(), Object\setMetadata(), and Container\updateMetadata().
name | ( | ) |
Get the name.
Returns the name of an object. If the name has been overwritten using setName(), this will return the latest (overwritten) name.
string |
Definition at line 207 of file Object.php.
References $name.
Referenced by Object\__construct(), Container\copy(), Container\save(), Object\setName(), and Container\updateMetadata().
removeHeaders | ( | $keys | ) |
Remove headers.
This takes an array of header names, and removes any matching headers. Typically, only headers set by setAdditionalHeaders() are removed from an Object. (RemoteObject works differently).
array | $keys | The header names to be removed. |
HPCloud::Storage::ObjectStorage::Object |
Reimplemented in RemoteObject.
Definition at line 516 of file Object.php.
References Object\additionalHeaders().
setAdditionalHeaders | ( | $headers | ) |
Set additional headers for storage.
Headers set here will be added to the HTTP request during save operations. They are not merged into existing headers until save-time.
This provides a mechanism for adding extension headers. CORS headers and possibly others are stored by Swift, but have no semantic value to Swift or to popular user agents.
There are a few things to note about this mechanism:
array | $headers | An associative array where each name is an HTTP header name, and each value is the HTTP header value. No encoding or escaping is done. |
HPCloud::Storage::ObjectStorage::Object |
Definition at line 481 of file Object.php.
References Object\additionalHeaders().
setContent | ( | $content, | |
$type = NULL |
|||
) |
Set the content for this object.
Place the content into the object. Typically, this is string content that will be stored remotely.
PHP's string is backed by a robust system that can accomodate moderately sized files. However, it is best to keep strings short (<2MB, for example – test for your own system's sweet spot). Larger data may be better handled with file system entries or database storage.
Note that the OpenStack will not allow files larger than 5G, and PHP will likely croak well before that marker. So use discretion.
string | $content | The content of the object. |
string | $type | The content type (MIME type). This can be set here for convenience, or you can call setContentType() directly. |
HPCloud::Storage::ObjectStorage::Object |
Definition at line 285 of file Object.php.
References $content, Object\content(), and Object\contentType().
Referenced by RemoteObject\content(), and RemoteObject\refresh().
setContentType | ( | $type | ) |
Set the content type (MIME type) for the object.
Object storage is, to a certain degree, content-type aware. For that reason, a content type is mandatory.
The default MIME type used is application/octet-stream
, which is the generic content type for a byte stream. Where possible, you should set a more accurate content type.
All HTTP type options are allowed. So, for example, you can add a charset to a text type:
Content type is not parsed or verified locally (though it is remotely). It can be dangerous, too, to allow users to specify a content type.
string | $type | A valid content type. |
HPCloud::Storage::ObjectStorage::Object |
Definition at line 242 of file Object.php.
References Object\contentType().
Referenced by RemoteObject\extractFromHeaders().
setDisposition | ( | $disposition | ) |
Set the content disposition.
This makes it possible to have the file act like a download (in a browser or similar agent), even if the MIME type normally triggers a display.
The typical value for this is:
A disposition string should not include any newline characters or binary data.
string | $disposition | A valid disposition declaration. These are defined in various HTTP specifications. |
HPCloud::Storage::ObjectStorage::Object |
Definition at line 424 of file Object.php.
Referenced by RemoteObject\extractFromHeaders().
setEncoding | ( | $encoding | ) |
Set the encoding for a file.
You can use content encoding on compressed content to indicate to the receiving agent that a file is encoded using a specific compression type.
Typical compression types are 'gzip', 'zip', and 'compress', though many others exist.
This allows you, for example, to save a zipped file, yet preserve its underlying content type. For example, for a gzipped text/plain file, you can set the content type to "text/plain" and the encoding to "gzip". This allows many user agents to receive the compressed data and automatically decompress them and display them correctly.
string | $encoding | A valid encoding type. |
HPCloud::Storage::ObjectStorage::Object |
Definition at line 379 of file Object.php.
Referenced by RemoteObject\extractFromHeaders().
setMetadata | ( | array | $array | ) |
Set the metadata.
OpenStack allows you to specify metadata for a file. Metadata items must follow these conventions:
(The docs are ambiguous – they say chars, but they may mean bytes.)
This library does only minimal processing of metadata, and does no error checking, escaping, etc. This is up to the implementor. The OpenStack Swift implementation does not dictate what encoding is used, though it suggests url encoding of both name and values.
Currently, no length checking is performed in the library, nor is any encoding of the data performed.
IMPORTANT: Current versions of OpenStack Swift normalize metadata names so that the name is always given an initial capital leter. That is, foo
becomes Foo
.
array | $array | An associative array of metadata names to values. |
HPCloud::Storage::ObjectStorage::Object |
Definition at line 155 of file Object.php.
References Object\metadata().
Referenced by RemoteObject\extractFromHeaders().
setName | ( | $name | ) |
Override (change) the name of an object.
Note that this changes only the local copy of an object. It does not rename the remote copy. In fact, changing the local name and then saving it will result in a new object being created in the object store.
To copy an object, see HPCloud::Storage::ObjectStorage::Container::copyObject().
string | $name | A file or object name. |
HPCloud::Storage::ObjectStorage::Object |
Definition at line 192 of file Object.php.
References $name, and Object\name().
|
protected |
Extension mechanism for new headers.
Definition at line 92 of file Object.php.
Referenced by RemoteObject\additionalHeaders().
|
protected |
The content.
Subclasses needn't use this to store an object's content, as they may prefer filesystem backing.
Definition at line 73 of file Object.php.
|
protected |
Definition at line 87 of file Object.php.
|
protected |
Definition at line 86 of file Object.php.
|
protected |
The content type.
The default type is 'application/octet-stream', which marks this as a generic byte stream.
Definition at line 80 of file Object.php.
|
protected |
Associative array of stored metadata.
Definition at line 84 of file Object.php.
|
protected |
The name of the object.
This can be path-like, subject to OpenStack's definition of "path-like".
Definition at line 65 of file Object.php.
const DEFAULT_CONTENT_TYPE = 'application/octet-stream' |
Definition at line 57 of file Object.php.