OpenCloud/ObjectStore/DataObject.php

Properties

Description

A core object in the Object Storage service (Swift).

Classes

DataObject

Properties

 
 
No 
No 

Description

A DataObject is an object in the ObjectStore
This class uses the name DataObject because "Object" is too generic and conflicts with certain PHP keywords.

Methods

CDNURL, Container, Copy, Create, Delete, Fetch, PublicURL, PurgeCDN, SaveToFilename, SaveToStream, SaveToString, Service, SetData, SetParams, TempUrl, Update, UpdateMetadata, Url, __construct, _guess_content_type, getETag, isRealFile,

CDNURL( ) : string

Description

Returns the CDN URL (for managing the object)
Note that the DataObject::PublicURL() method is used to return the publicly-available URL of the object, while the CDNURL() is used to manage the object.

Return value

Type Description
string

Container( ) : \OpenCloud\ObjectStore\Container

Description

Returns the container of the object

Return value

Type Description
\OpenCloud\ObjectStore\Container

Copy( \OpenCloud\ObjectStore\DataObject   $target, ) : n/a

Description

Copies the object to another container/object
Note that this function, because it operates within the Object Store itself, is much faster than downloading the object and re-uploading it to a new object.

Arguments

Name Type Description Default
$target \OpenCloud\ObjectStore\DataObject

the target of the COPY command

Return value

Type Description
n/a n/a

Create( array   $params = array(), string   $filename = null,   $extractArchive = null, ) : boolean

Description

Creates (or updates; both the same) an instance of the object

Arguments

Name Type Description Default
$params array

an optional associative array that can contain the 'name' and 'content_type' of the object

array()
$filename string

if provided, then the object is loaded from the specified file

null
$extractArchive n/a null

Return value

Type Description
boolean

Tags

Name Description
api
throws

Delete( array   $params = array(), ) : \OpenCloud\ObjectStore\HttpResponse

Description

Deletes an object from the Object Store
Note that we can delete without retrieving by specifying the name in the parameter array.

Arguments

Name Type Description Default
$params array

an array of parameters

array()

Return value

Type Description
\OpenCloud\ObjectStore\HttpResponse if successful; FALSE if not

Tags

Name Description
api
throws

Fetch( ) : void

Description

Retrieves a single object, parses headers

Return value

Type Description
void

Tags

Name Description
throws ObjFetchError

PublicURL( string   $type = null, ) : string

Description

Returns the object's Public CDN URL, if available

Arguments

Name Type Description Default
$type string

can be 'streaming', 'ssl', or anything else for the default URL.

null

Return value

Type Description
string

Tags

Name Description
api

PurgeCDN( string   $email, ) : void

Description

Purges the object from the CDN
Note that the object will still be served up to the time of its TTL value.

Arguments

Name Type Description Default
$email string

An email address that will be notified when the object is purged.

Return value

Type Description
void

Tags

Name Description
api
throws if the container is not CDN-enabled
throws if there is an HTTP error in the transaction

SaveToFilename( string   $filename, ) : boolean

Description

Saves the object's data to local filename
Given a local filename, the Object's data will be written to the newly created file. Example: # ... authentication/connection/container code excluded # ... see previous examples # Whoops! I deleted my local README, let me download/save it # $my_docs = $conn->get_container("documents"); $doc = $my_docs->get_object("README"); $doc->SaveToFilename("/home/ej/cloudfiles/readme.restored");

Arguments

Name Type Description Default
$filename string

name of local file to write data to

Return value

Type Description
boolean <kbd>TRUE</kbd> if successful

Tags

Name Description
throws error opening file
throws unexpected response

SaveToStream(   $resource, ) : boolean

Description

Saves the object's to a stream filename
Given a local filename, the Object's data will be written to the stream Example: # ... authentication/connection/container code excluded # ... see previous examples # If I want to write the README to a temporary memory string I # do : # $my_docs = $conn->get_container("documents"); $doc = $my_docs->DataObject(array("name"=>"README")); $fp = fopen('php://temp', 'r+'); $doc->SaveToStream($fp); fclose($fp);

Arguments

Name Type Description Default
$resource n/a

Return value

Type Description
boolean <kbd>TRUE</kbd> if successful

Tags

Name Description
throws error opening file
throws unexpected response

SaveToString( ) : string

Description

Return object's data as a string

Return value

Type Description
string the entire object

Service( ) : n/a

Description

Returns the service associated with this object
It's actually the object's container's service, so this method will simplify things a bit.

Return value

Type Description
n/a n/a

SetData( string   $data, ) : void

Description

Sets object data from string
This is a convenience function to permit the use of other technologies for setting an object's content.

Arguments

Name Type Description Default
$data string

Return value

Type Description
void

SetParams( array   $params, ) : void

Description

Sets parameters from an array; validates them

Arguments

Name Type Description Default
$params array

associative array of parameters

Return value

Type Description
void

Tags

Name Description
throws

TempUrl( string   $secret, integer   $expires, string   $method, ) : string

Description

returns the TEMP_URL for the object
Some notes: * The `$secret` value is arbitrary; it must match the value set for the `X-Account-Meta-Temp-URL-Key` on the account level. This can be set by calling `$service->SetTempUrlSecret($secret)`. * The `$expires` value is the number of seconds you want the temporary URL to be valid for. For example, use `60` to make it valid for a minute * The `$method` must be either GET or PUT. No other methods are supported.

Arguments

Name Type Description Default
$secret string

the shared secret

$expires integer

the expiration time (in seconds)

$method string

either GET or PUT

Return value

Type Description
string the temporary URL

Update( array   $params = array(), string   $filename = '', ) : boolean

Description

Update() is provided as an alias for the Create() method
Since update and create both use a PUT request, the different functions may allow the developer to distinguish between the semantics in his or her application.

Arguments

Name Type Description Default
$params array

an optional associative array that can contain the 'name' and 'type' of the object

array()
$filename string

if provided, the object is loaded from the file

''

Return value

Type Description
boolean

Tags

Name Description
api

UpdateMetadata( array   $params = array(), ) : boolean

Description

UpdateMetadata() - updates headers
Updates metadata headers

Arguments

Name Type Description Default
$params array

an optional associative array that can contain the 'name' and 'type' of the object

array()

Return value

Type Description
boolean

Tags

Name Description
api

Url( string   $subresource = '', ) : string

Description

Returns the URL of the data object
If the object is new and doesn't have a name, then an exception is thrown.

Arguments

Name Type Description Default
$subresource string

Not used

''

Return value

Type Description
string

Tags

Name Description
throws

__construct( \OpenCloud\ObjectStore\Container   $container, mixed   $cdata = NULL, ) : void

Description

A DataObject is related to a container and has a name
If `$name` is specified, then it attempts to retrieve the object from the object store.

Arguments

Name Type Description Default
$container \OpenCloud\ObjectStore\Container

the container holding this object

$cdata mixed

if an object or array, it is treated as values with which to populate the object. If it is a string, it is treated as a name and the object's info is retrieved from the service.

NULL

Return value

Type Description
void

_guess_content_type( string   $handle, ) : boolean

Description

Performs an internal check to get the proper MIME type for an object
This function would go over the available PHP methods to get the MIME type. By default it will try to use the PHP fileinfo library which is available from PHP 5.3 or as an PECL extension (http://pecl.php.net/package/Fileinfo). It will get the magic file by default from the system wide file which is usually available in /usr/share/magic on Unix or try to use the file specified in the source directory of the API (share directory). if fileinfo is not available it will try to use the internal mime_content_type function.

Arguments

Name Type Description Default
$handle string

name of file or buffer to guess the type from

Return value

Type Description
boolean <kbd>TRUE</kbd> if successful

Tags

Name Description
throws

getETag( ) : string

Description

Returns the object's MD5 checksum
Accessor method for reading Object's private ETag attribute.

Return value

Type Description
string MD5 checksum hexidecimal string

Tags

Name Description
api

isRealFile(   $filename, ) : n/a

Arguments

Name Type Description Default
$filename n/a

Return value

Type Description
n/a n/a

Properties

$bytes, $container, $content_length, $content_type, $data, $etag, $extra_headers, $hash, $header_translate, $last_modified, $name, $send_etag,

  public  $bytes =




  private  $container =




  public  $content_length =




  public  $content_type =




  private  $data =




  private  $etag =




  public  $extra_headers =




  public  $hash =




  private  $header_translate = array('Etag' => 'hash', 'Last-Modified' => 'last_modified')




  public  $last_modified =




  public  $name =




  public  $send_etag = TRUE




Documentation was generated by phpDocumentor 2.0.0b6 .

Namespaces

Packages