CloudFusion

Core functionality and default settings shared across all CloudFusion classes.  This is a base class containing shared functionality.  All methods and properties in this class are inherited by the service-specific classes.

Version

2009.10.10

Copyright

2006-2010 Ryan Parman, Foleeo, Inc., and contributors.

License

Simplified BSD Licensehttp://opensource.org/licenses/bsd-license.php

See Also

CloudFusionhttp://getcloudfusion.com

Constants

CLOUDFUSION_NAME

Name of the software.

CLOUDFUSION_VERSION

Version of the software.

CLOUDFUSION_BUILD

Build ID of the software.

CLOUDFUSION_URL

URL to learn more about the software.

CLOUDFUSION_USERAGENT

User agent string used to identify CloudFusion

CloudFusion/2.5 (Cloud Computing Toolkit; http://getcloudfusion.com) Build/20090824000000

DATE_FORMAT_RFC2616

Define the RFC 2616-compliant date format

DATE_FORMAT_ISO8601

Define the ISO-8601-compliant date format

DATE_FORMAT_MYSQL

Define the MySQL-compliant date format

HTTP_GET

HTTP method type: Get

HTTP_POST

HTTP method type: Post

HTTP_PUT

HTTP method type: Put

HTTP_DELETE

HTTP method type: Delete

HTTP_HEAD

HTTP method type: Head

CloudFusion

Container for all shared methods.  This is not intended to be instantiated directly, but is extended by the service-specific classes.

Properties

key

The Amazon API Key.  This is inherited by all service-specific classes.

secret_key

The Amazon API Secret Key.  This is inherited by all service-specific classes.

account_id

The Amazon Account ID, sans hyphens.  This is inherited by all service-specific classes.

assoc_id

The Amazon Associates ID.  This is inherited by all service-specific classes.

util

Handle for the utility functions.  This is inherited by all service-specific classes.

service

An identifier for the current AWS service.  This is inherited by all service-specific classes.

api_version

The supported API version.  This is inherited by all service-specific classes.

utilities_class

The default class to use for Utilities (defaults to CFUtilities).  This is inherited by all service-specific classes.

request_class

The default class to use for HTTP Requests (defaults to RequestCore).  This is inherited by all service-specific classes.

response_class

The default class to use for HTTP Responses (defaults to ResponseCore).  This is inherited by all service-specific classes.

adjust_offset

The number of seconds to adjust the request timestamp by (defaults to 0).  This is inherited by all service-specific classes.

enable_ssl

Whether SSL/HTTPS should be enabled by default.  This is inherited by all service-specific classes.

set_proxy

Sets the proxy to use for connecting.  This is inherited by all service-specific classes.

devpay_tokens

Stores the Amazon DevPay tokens to use, if any.  This is inherited by all service-specific classes.

set_hostname

Stores the alternate hostname to use, if any.  This is inherited by all service-specific classes.

Functions

autoloader()

public static function autoloader($class)

Automatically load classes that aren’t included.

Access

public static

Parameters

class_namestring (Required) The classname to load.

Returns

void

__construct()

public function __construct($key =  null,
$secret_key =  null,
$account_id =  null,
$assoc_id =  null)

The constructor.  You would not normally instantiate this class directly.  Rather, you would instantiate a service-specific class.

Access

public

Parameters

keystring (Optional) Your Amazon API Key.  If blank, it will look for the AWS_KEY constant.
secret_keystring (Optional) Your Amazon API Secret Key.  If blank, it will look for the AWS_SECRET_KEY constant.
account_idstring (Optional) Your Amazon account ID without the hyphens.  Required for EC2.  If blank, it will look for the AWS_ACCOUNT_ID constant.
assoc_idstring (Optional) Your Amazon Associates ID.  Required for AAWS.  If blank, it will look for the AWS_ASSOC_ID constant.

Returns

boolean FALSE if no valid values are set, otherwise true.

adjust_offset()

public function adjust_offset($seconds)

Allows you to adjust the current time, for occasions when your server is out of sync with Amazon’s servers.  This method is inherited by all service-specific classes.  You would call this from those classes, not CloudFusion().

Access

public

Parameters

secondsinteger (Required) The number of seconds to adjust the sent timestamp by.

Returns

void

Examples

CloudFusion - adjust_offset
<?php

// Dependencies
require_once 'cloudfusion.class.php';

/**
 * You wouldn't normally call this class directly. These methods
 * are inherited by the service-specific classes.
 */

// Adjust offset
$cf = new CloudFusion();
$cf->adjust_offset(123456789);

// Test if the value was set
var_dump($cf->adjust_offset);

/** [Expected output] 
int(123456789)
*/
?>

set_proxy()

public function set_proxy($proxy)

Set the proxy settings to use for connecting.  This method is inherited by all service-specific classes.  You would call this from those classes, not CloudFusion().

Access

public

Parameters

proxystring (Required) Accepts proxy credentials in the following format: proxy://user:pass@hostname:port

Returns

void

Examples

CloudFusion - set_proxy
<?php

// Dependencies
require_once 'cloudfusion.class.php';

/**
 * You wouldn't normally call this class directly. These methods
 * are inherited by the service-specific classes.
 */

// Adjust offset
$f = new CloudFusion();
$f->set_proxy('test');

// Test if the value was set
var_dump($f->set_proxy);

/** [Expected output] 
string(4) "test"*/
?>

set_hostname()

public function set_hostname($hostname)

Set the hostname to use for connecting.  This is useful for alternate services that are API-compatible with AWS, but run from a different hostname.  This method is inherited by all service-specific classes.  You would call this from those classes, not CloudFusion().

Access

public

Parameters

hostnamestring (Required) The alternate hostname to use in place of the default one.  Useful for API-compatible applications living on different hostnames.

Returns

void

Examples

CloudFusion - set_hostname
<?php

// Dependencies
require_once 'cloudfusion.class.php';

/**
 * You wouldn't normally call this class directly. These methods
 * are inherited by the service-specific classes.
 */

// Adjust offset
$f = new CloudFusion();
$f->set_hostname('example.com');

// Test if the value was set
var_dump($f->hostname);

/** [Expected output] 
string(11) "example.com"
*/
?>

disable_ssl()

public function disable_ssl()

Disables SSL/HTTPS connections for hosts that don’t support them.  Some services, however, still REQUIRE SSL support.  This method is inherited by all service-specific classes.  You would call this from those classes, not CloudFusion().

Access

public

Returns

void

Examples

CloudFusion - disable_ssl
<?php

// Dependencies
require_once 'cloudfusion.class.php';

/**
 * You wouldn't normally call this class directly. These methods
 * are inherited by the service-specific classes.
 */

// Adjust offset
$f = new CloudFusion();
$f->disable_ssl(true);

// Test if the value was set
var_dump($f->enable_ssl);

/** [Expected output] 
bool(false)
*/
?>

set_utilities_class()

function set_utilities_class($class =  'CFUtilities')

Set a custom class for this functionality.  Perfect for extending/overriding existing classes with new functionality.  This method is inherited by all service-specific classes.  You would call this from those classes, not CloudFusion().

Access

public

Parameters

classstring (Optional) The name of the new class to use for this functionality.  Defaults to the default class.

Returns

void

Examples

CloudFusion - set_utilities_class
<?php

// Dependencies
require_once 'cloudfusion.class.php';

/**
 * You wouldn't normally call this class directly. These methods
 * are inherited by the service-specific classes.
 */

// Custom class to extend CFUtilities
class TestUtilities extends CFUtilities
{
	public function test_method()
	{
		return true;
	}
}

// Instantiate class and set new class
$f = new CloudFusion();
$f->set_utilities_class('TestUtilities');

// Test if the value was set
var_dump($f->util->test_method());

/** [Expected output] 
bool(true)
*/
?>

set_request_class()

function set_request_class($class =  'RequestCore')

Set a custom class for this functionality.  Perfect for extending/overriding existing classes with new functionality.  This method is inherited by all service-specific classes.  You would call this from those classes, not CloudFusion().

Access

public

Parameters

classstring (Optional) The name of the new class to use for this functionality.  Defaults to the default class.

Returns

void

Examples

CloudFusion - set_request_class
<?php

// Dependencies
require_once 'cloudfusion.class.php';

/**
 * You wouldn't normally call this class directly. These methods
 * are inherited by the service-specific classes.
 */

// Custom class to extend RequestCore
class TestRequestCore extends RequestCore
{
	public function test_method()
	{
		return true;
	}
}

// Instantiate class and set new class
$f = new CloudFusion();
$f->set_request_class('TestRequestCore');

// Test if the value was set
var_dump($f->request_class);

/** [Expected output] 
string(15) "TestRequestCore"
*/
?>

set_response_class()

function set_response_class($class =  'ResponseCore')

Set a custom class for this functionality.  Perfect for extending/overriding existing classes with new functionality.  This method is inherited by all service-specific classes.  You would call this from those classes, not CloudFusion().

Access

public

Parameters

classstring (Optional) The name of the new class to use for this functionality.  Defaults to the default class.

Returns

void

Examples

CloudFusion - set_response_class
<?php

// Dependencies
require_once 'cloudfusion.class.php';

/**
 * You wouldn't normally call this class directly. These methods
 * are inherited by the service-specific classes.
 */

// Custom class to extend ResponseCore
class TestResponseCore extends ResponseCore
{
	public function test_method()
	{
		return true;
	}
}

// Instantiate class and set new class
$f = new CloudFusion();
$f->set_response_class('TestResponseCore');

// Test if the value was set
var_dump($f->response_class);

/** [Expected output] 
string(16) "TestResponseCore"
*/
?>

authenticate()

public function authenticate($action,  
$opt =  null,
$domain =  null,
$message =  null)

Default, shared method for authenticating a connection to AWS.  Overridden on a class-by-class basis as necessary.  This method is inherited by all service-specific classes.  This should not be used directly unless you’re writing custom methods for this class.

Access

public

Parameters

actionstring (Required) Indicates the action to perform.
optarray (Optional) Associative array of parameters for authenticating.  See the individual methods for allowed keys.
domainstring (Optional) The URL of the queue to perform the action on.
messagestring (Optional) This parameter is only used by the send_message() method.

Returns

ResponseCore object

cache_response()

public function cache_response($method,  
$location,  
$expires,  
$params =  null,
$gzip =  true)

Caches a ResponseCore object using the preferred caching method.  This method is inherited by all service-specific classes.  You would call this from those classes, not CloudFusion().

Access

public

Parameters

methodstring (Required) The method of the current object that you want to execute and cache the response for.  If the method is not in the $this scope, pass in an array where the correct scope is in the [0] position and the method name is in the [1] position.
locationstring (Required) The location to store the cache object in.  This may vary by cache method.  See below.
expiresinteger (Required) The number of seconds until a cache object is considered stale.
paramsarray (Optional) An indexed array of parameters to pass to the aforementioned method, where array[0] represents the first parameter, array[1] is the second, etc.
gzipboolean (Optional) Whether data should be gzipped before being stored.  Defaults to true.

Example values for $location

FileLocal file system paths such as ./cache (relative) or /tmp/cache/cloudfusion (absolute).  Location must be server-writable.
APCPass in ‘apc’ to use this lightweight cache.  You must have the APC extension installed.  http://php.net/apc
XCachePass in ‘xcache’ to use this lightweight cache.  You must have the XCache extension installed.  http://xcache.lighttpd.net/
MemcachedPass in an indexed array of associative arrays.  Each associative array should have a ‘host’ and a ‘port’ value representing a Memcached server to connect to.
PDOA URL-style string (e.g. pdo.mysql://user:pass@localhost/cloudfusion_cache) or a standard DSN-style string (e.g. pdo.sqlite:/sqlite/cloudfusion_cache.db).  MUST be prefixed with ‘pdo.’.  See CachePDO and http://php.net/pdo for more details.

Returns

ResponseCore object

Examples

AmazonSDB::cache_response CacheAPC
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// Instantiate
$sdb = new AmazonSDB();

// First time pulls live data
$response = $sdb->cache_response('list_domains', 'apc', 10);
var_dump($response->isOK());

// Second time pulls from cache
$response = $sdb->cache_response('list_domains', 'apc', 10);
var_dump($response->isOK());

/** [Expected output] 
bool(true)
bool(true)
*/
?>
AmazonSDB::cache_response CacheFile
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// Instantiate
$sdb = new AmazonSDB();

// First time pulls live data
$response = $sdb->cache_response('list_domains', dirname(dirname(__FILE__)) . '/_cache', 10);
var_dump($response->isOK());

// Second time pulls from cache
$response = $sdb->cache_response('list_domains', dirname(dirname(__FILE__)) . '/_cache', 10);
var_dump($response->isOK());

/** [Expected output] 
bool(true)
bool(true)
*/
?>
AmazonSDB::cache_response CacheMC
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// Instantiate
$sdb = new AmazonSDB();

// First time pulls live data
$response = $sdb->cache_response('list_domains', array(
	array('host' => '127.0.0.1')
), 10);
var_dump($response->isOK());

// Second time pulls from cache
$response = $sdb->cache_response('list_domains', array(
	array('host' => '127.0.0.1')
), 10);
var_dump($response->isOK());

/** [Expected output] 
bool(true)
bool(true)
*/
?>
AmazonSDB::cache_response CachePDO:SQLite
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// Instantiate
$sdb = new AmazonSDB();

// First time pulls live data
$response = $sdb->cache_response('list_domains', 'pdo.sqlite:' . dirname(dirname(__FILE__)) . '/_cache/sqlite.db', 10);
var_dump($response->isOK());

// Second time pulls from cache
$response = $sdb->cache_response('list_domains', 'pdo.sqlite:' . dirname(dirname(__FILE__)) . '/_cache/sqlite.db', 10);
var_dump($response->isOK());

/** [Expected output] 
bool(true)
bool(true)
*/
?>
AmazonSDB::cache_response MultiCurl CacheAPC
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// Instantiate
$sdb = new AmazonSDB();

// Prepare for parallel requests
$handles = array();
$handles[] = $sdb->list_domains(array(
	'returnCurlHandle' => true
));
$handles[] = $sdb->list_domains(array(
	'returnCurlHandle' => true
));

// Instantiate
$http = new RequestCore(null);

// First time pulls live data
$response = $sdb->cache_response(array($http, 'send_multi_request'), 'apc', 60, array($handles));
var_dump($response[0]->isOK());
var_dump($response[1]->isOK());

// Second time pulls from cache
$response = $sdb->cache_response(array($http, 'send_multi_request'), 'apc', 60, array($handles));
var_dump($response[0]->isOK());
var_dump($response[1]->isOK());

/** [Expected output] 
bool(true)
bool(true)
bool(true)
bool(true)
*/
?>
AmazonSDB::cache_response MultiCurl CacheFile
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// Instantiate
$sdb = new AmazonSDB();

// Prepare for parallel requests
$handles = array();
$handles[] = $sdb->list_domains(array(
	'returnCurlHandle' => true
));
$handles[] = $sdb->list_domains(array(
	'returnCurlHandle' => true
));

// Instantiate
$http = new RequestCore(null);

// First time pulls live data
$response = $sdb->cache_response(array($http, 'send_multi_request'), dirname(dirname(__FILE__)) . '/_cache', 60, array($handles));
var_dump($response[0]->isOK());
var_dump($response[1]->isOK());

// Second time pulls from cache
$response = $sdb->cache_response(array($http, 'send_multi_request'), dirname(dirname(__FILE__)) . '/_cache', 60, array($handles));
var_dump($response[0]->isOK());
var_dump($response[1]->isOK());

/** [Expected output] 
bool(true)
bool(true)
bool(true)
bool(true)
*/
?>

delete_cache_response()

public function delete_cache_response($method,  
$location,  
$params =  null)

Deletes a cached ResponseCore object using the preferred caching method.

Access

public

Parameters

methodstring (Required) The same method you used while caching initially.
locationstring (Required) The same location you used while caching initially.
paramsarray (Optional) The same parameters that you used while caching initially.

Example values for $location

FileLocal file system paths such as ./cache (relative) or /tmp/cache/tarzan (absolute).  Location must be server-writable.
APCPass in ‘apc’ to use this lightweight cache.  You must have the APC extension installed.  http://php.net/apc
XCachePass in ‘xcache’ to use this lightweight cache.  You must have the XCache extension installed.  http://xcache.lighttpd.net/
MemcachedPass in an indexed array of associative arrays.  Each associative array should have a ‘host’ and a ‘port’ value representing a Memcached server to connect to.
PDOA URL-style string (e.g. pdo.mysql://user:pass@localhost/tarzan_cache) or a standard DSN-style string (e.g. pdo.sqlite:/sqlite/tarzan_cache.db).  MUST be prefixed with ‘pdo.’.  See CachePDO and http://php.net/pdo for more details.

Returns

boolean TRUE if cached object exists and is successfully deleted, otherwise FALSE

Examples

AmazonSDB::delete_cache_response CacheAPC
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// Instantiate
$sdb = new AmazonSDB();

// Delete the data
$response = $sdb->delete_cache_response('list_domains', 'apc');
var_dump($response);

/** [Expected output] 
bool(false)
*/
?>
AmazonSDB::delete_cache_response CacheFile
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// Instantiate
$sdb = new AmazonSDB();

// Delete the data
$response = $sdb->delete_cache_response('list_domains', dirname(dirname(__FILE__)) . '/_cache');
var_dump($response);

/** [Expected output] 
bool(true)
*/
?>
AmazonSDB::delete_cache_response CacheMC
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// Instantiate
$sdb = new AmazonSDB();

// Delete the data
$response = $sdb->delete_cache_response('list_domains', array(
	array('host' => '127.0.0.1')
));
var_dump($response);

/** [Expected output] 
bool(true)
*/
?>
AmazonSDB::delete_cache_response CachePDO:SQLite
<?php

// Dependencies
require_once 'cloudfusion.class.php';

// Instantiate
$sdb = new AmazonSDB();

// Delete the data
$response = $sdb->delete_cache_response('list_domains', 'pdo.sqlite:' . dirname(dirname(__FILE__)) . '/_cache/sqlite.db');
var_dump($response);

/** [Expected output] 
bool(true)
*/
?>