php-cloudfiles
[ class tree: php-cloudfiles ] [ index: php-cloudfiles ] [ all elements ]

Class: CF_Connection

Source Location: /cloudfiles.php

Class Overview


Class for establishing connections to the Cloud Files storage system.


Variables

Methods



Class Details

[line 341]
Class for establishing connections to the Cloud Files storage system.

Connection instances are used to communicate with the storage system at the account level; listing and deleting Containers and returning Container instances.

Example:

  1.  # Create the authentication instance
  2.  #
  3.  $auth new CF_Authentication("username""api_key");
  4.  
  5.  # Perform authentication request
  6.  #
  7.  $auth->authenticate();
  8.  
  9.  # Create a connection to the storage/cdn system(s) and pass in the
  10.  # validated CF_Authentication instance.
  11.  #
  12.  $conn new CF_Connection($auth);
  13.  
  14.  # NOTE: Some versions of cURL include an outdated certificate authority (CA)
  15.  #       file.  This API ships with a newer version obtained directly from
  16.  #       cURL's web site (http://curl.haxx.se).  To use the newer CA bundle,
  17.  #       call the CF_Authentication instance's 'ssl_use_cabundle()' method.
  18.  #
  19.  # $conn->ssl_use_cabundle(); # bypass cURL's old CA bundle




[ Top ]


Class Variables

$cfs_auth =

[line 345]



Tags:

access:  public

Type:   mixed


[ Top ]

$cfs_http =

[line 344]



Tags:

access:  public

Type:   mixed


[ Top ]

$dbug =

[line 343]



Tags:

access:  public

Type:   mixed


[ Top ]



Class Methods


constructor __construct [line 380]

CF_Connection __construct( obj $cfs_auth, [boolean $servicenet = False])

Pass in a previously authenticated CF_Authentication instance.

Example:

  1.  # Create the authentication instance
  2.  #
  3.  $auth new CF_Authentication("username""api_key");
  4.  
  5.  # Perform authentication request
  6.  #
  7.  $auth->authenticate();
  8.  
  9.  # Create a connection to the storage/cdn system(s) and pass in the
  10.  # validated CF_Authentication instance.
  11.  #
  12.  $conn new CF_Connection($auth);
  13.  
  14.  # If you are connecting via Rackspace servers and have access
  15.  # to the servicenet network you can set the $servicenet to True
  16.  # like this.
  17.  
  18.  $conn new CF_Connection($auth$servicenet=True);

If the environement variable RACKSPACE_SERVICENET is defined it will force to connect via the servicenet.




Tags:

throws:  AuthenticationException not authenticated


Parameters:

obj   $cfs_auth   previously authenticated CF_Authentication instance
boolean   $servicenet   enable/disable access via Rackspace servicenet.

[ Top ]

method close [line 419]

void close( )

Close a connection

Example:

  1.  $conn->close();

Will close all current cUrl active connections.




Tags:

access:  public


[ Top ]

method create_container [line 478]

CF_Container create_container( [string $container_name = NULL])

Create a Container

Given a Container name, return a Container instance, creating a new remote Container if it does not exit.

Example:

  1.  # ... authentication code excluded (see previous examples) ...
  2.  #
  3.  $conn new CF_Authentication($auth);
  4.  
  5.  $images $conn->create_container("my photos");




Tags:

throws:  SyntaxException invalid name
throws:  InvalidResponseException unexpected response


Parameters:

string   $container_name   container name

[ Top ]

method delete_container [line 535]

boolean delete_container( [string|obj $container = NULL])

Delete a Container

Given either a Container instance or name, remove the remote Container. The Container must be empty prior to removing it.

Example:

  1.  # ... authentication code excluded (see previous examples) ...
  2.  #
  3.  $conn new CF_Authentication($auth);
  4.  
  5.  $conn->delete_container("my photos");




Tags:

return:  True if successfully deleted
throws:  SyntaxException missing proper argument
throws:  InvalidResponseException invalid response
throws:  NonEmptyContainerException container not empty
throws:  NoSuchContainerException remote container does not exist


Parameters:

string|obj   $container   container name or instance

[ Top ]

method get_container [line 597]

container get_container( [string $container_name = NULL])

Return a Container instance

For the given name, return a Container instance if the remote Container exists, otherwise throw a Not Found exception.

Example:

  1.  # ... authentication code excluded (see previous examples) ...
  2.  #
  3.  $conn new CF_Authentication($auth);
  4.  
  5.  $images $conn->get_container("my photos");
  6.  print "Number of Objects: " $images->count . "\n";
  7.  print "Bytes stored in container: " $images->bytes "\n";




Tags:

return:  CF_Container instance
throws:  NoSuchContainerException thrown if no remote Container
throws:  InvalidResponseException unexpected response


Parameters:

string   $container_name   name of the remote Container

[ Top ]

method get_containers [line 639]

array get_containers( [ $limit = 0], [ $marker = NULL])

Return array of Container instances

Return an array of CF_Container instances on the account. The instances will be fully populated with Container attributes (bytes stored and Object count)

Example:

  1.  # ... authentication code excluded (see previous examples) ...
  2.  #
  3.  $conn new CF_Authentication($auth);
  4.  
  5.  $clist $conn->get_containers();
  6.  foreach ($clist as $cont{
  7.      print "Container name: " $cont->name "\n";
  8.      print "Number of Objects: " $cont->count . "\n";
  9.      print "Bytes stored in container: " $cont->bytes "\n";
  10.  }




Tags:

return:  An array of CF_Container instances
throws:  InvalidResponseException unexpected response


Parameters:

   $limit  
   $marker  

[ Top ]

method get_info [line 444]

array get_info( )

Cloud Files account information

Return an array of two floats (since PHP only supports 32-bit integers); number of containers on the account and total bytes used for the account.

Example:

  1.  # ... authentication code excluded (see previous examples) ...
  2.  #
  3.  $conn new CF_Authentication($auth);
  4.  
  5.  list($quantity$bytes$conn->get_info();
  6.  print "Number of containers: " $quantity "\n";
  7.  print "Bytes stored in container: " $bytes "\n";




Tags:

return:  (number of containers, total bytes stored)
throws:  InvalidResponseException unexpected response


[ Top ]

method list_containers [line 683]

array list_containers( [integer $limit = 0], [string $marker = NULL])

Return list of remote Containers

Return an array of strings containing the names of all remote Containers.

Example:

  1.  # ... authentication code excluded (see previous examples) ...
  2.  #
  3.  $conn new CF_Authentication($auth);
  4.  
  5.  $container_list $conn->list_containers();
  6.  print_r($container_list);
  7.  Array
  8.  (
  9.      [0=> "my photos",
  10.      [1=> "my docs"
  11.  )




Tags:

return:  list of remote Containers
throws:  InvalidResponseException unexpected response


Parameters:

integer   $limit   restrict results to $limit Containers
string   $marker   return results greater than $marker

[ Top ]

method list_containers_info [line 731]

array list_containers_info( [integer $limit = 0], [string $marker = NULL])

Return array of information about remote Containers

Return a nested array structure of Container info.

Example:

  1.  # ... authentication code excluded (see previous examples) ...
  2.  #
  3.  
  4.  $container_info $conn->list_containers_info();
  5.  print_r($container_info);
  6.  Array
  7.  (
  8.      ["my photos"=>
  9.          Array
  10.          (
  11.              ["bytes"=> 78,
  12.              ["count"=> 2
  13.          )
  14.      ["docs"=>
  15.          Array
  16.          (
  17.              ["bytes"=> 37323,
  18.              ["count"=> 12
  19.          )
  20.  )




Tags:

return:  nested array structure of Container info
throws:  InvalidResponseException unexpected response


Parameters:

integer   $limit   restrict results to $limit Containers
string   $marker   return results greater than $marker

[ Top ]

method list_public_containers [line 773]

array list_public_containers( [bool $enabled_only = False])

Return list of Containers that have been published to the CDN.

Return an array of strings containing the names of published Containers. Note that this function returns the list of any Container that has ever been CDN-enabled regardless of it's existence in the storage system.

Example:

  1.  # ... authentication code excluded (see previous examples) ...
  2.  #
  3.  $conn new CF_Authentication($auth);
  4.  
  5.  $public_containers $conn->list_public_containers();
  6.  print_r($public_containers);
  7.  Array
  8.  (
  9.      [0=> "images",
  10.      [1=> "css",
  11.      [2=> "javascript"
  12.  )




Tags:

return:  list of published Container names
throws:  InvalidResponseException unexpected response


Parameters:

bool   $enabled_only   Will list all containers ever CDN enabled if * set to false or only currently enabled CDN containers if set to true. * Defaults to false.

[ Top ]

method setDebug [line 400]

void setDebug( boolean $bool)

Toggle debugging of instance and back-end HTTP module



Parameters:

boolean   $bool   enable/disable cURL debugging

[ Top ]

method set_read_progress_function [line 823]

void set_read_progress_function( string $func_name)

Set a user-supplied callback function to report download progress

The callback function is used to report incremental progress of a data download functions (e.g. $container->list_objects(), $obj->read(), etc). The specified function will be periodically called with the number of bytes transferred until the entire download is complete. This callback function can be useful for implementing "progress bars" for large downloads.

The specified callback function should take a single integer parameter.

  1.  function read_callback($bytes_transferred{
  2.      print ">> downloaded " $bytes_transferred " bytes.\n";
  3.      # ... do other things ...
  4.      return;
  5.  }
  6.  
  7.  $conn new CF_Connection($auth_obj);
  8.  $conn->set_read_progress_function("read_callback");
  9.  
  10.  # output would look like this:
  11.  #
  12.  >> downloaded 10 bytes.
  13.  >> downloaded 11 bytes.
  14.  Array
  15.  (
  16.       [0=> fuzzy.txt
  17.       [1=> space name
  18.  )




Parameters:

string   $func_name   the name of the user callback function

[ Top ]

method set_write_progress_function [line 859]

void set_write_progress_function( string $func_name)

Set a user-supplied callback function to report upload progress

The callback function is used to report incremental progress of a data upload functions (e.g. $obj->write() call). The specified function will be periodically called with the number of bytes transferred until the entire upload is complete. This callback function can be useful for implementing "progress bars" for large uploads/downloads.

The specified callback function should take a single integer parameter.

  1.  function write_callback($bytes_transferred{
  2.      print ">> uploaded " $bytes_transferred " bytes.\n";
  3.      # ... do other things ...
  4.      return;
  5.  }
  6.  
  7.  $conn new CF_Connection($auth_obj);
  8.  $conn->set_write_progress_function("write_callback");
  9.  $container $conn->create_container("stuff");
  10.  $obj $container->create_object("foo");
  11.  $obj->write("The callback function will be called during upload.");
  12.  
  13.  # output would look like this:
  14.  # >> uploaded 51 bytes.
  15.  #




Parameters:

string   $func_name   the name of the user callback function

[ Top ]

method ssl_use_cabundle [line 885]

void ssl_use_cabundle( [string $path = NULL])

Use the Certificate Authority bundle included with this API

Most versions of PHP with cURL support include an outdated Certificate Authority (CA) bundle (the file that lists all valid certificate signing authorities). The SSL certificates used by the Cloud Files storage system are perfectly valid but have been created/signed by a CA not listed in these outdated cURL distributions.

As a work-around, we've included an updated CA bundle obtained directly from cURL's web site (http://curl.haxx.se). You can direct the API to use this CA bundle by calling this method prior to making any remote calls. The best place to use this method is right after the CF_Authentication instance has been instantiated.

You can specify your own CA bundle by passing in the full pathname to the bundle. You can use the included CA bundle by leaving the argument blank.




Parameters:

string   $path   Specify path to CA bundle (default to included)

[ Top ]


Documentation generated on Wed, 07 Sep 2011 15:19:55 -0500 by phpDocumentor 1.4.3