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.
2009.10.10
2006-2010 Ryan Parman, Foleeo, Inc., and contributors.
| Simplified BSD License | http://opensource.org/licenses/bsd-license.php |
| CloudFusion | http://getcloudfusion.com |
Name of the software.
Version of the software.
Build ID of the software.
URL to learn more about the software.
User agent string used to identify CloudFusion
CloudFusion/2.5 (Cloud Computing Toolkit; http://getcloudfusion.com) Build/20090824000000
Define the RFC 2616-compliant date format
Define the ISO-8601-compliant date format
Define the MySQL-compliant date format
HTTP method type: Get
HTTP method type: Post
HTTP method type: Put
HTTP method type: Delete
HTTP method type: Head
Container for all shared methods. This is not intended to be instantiated directly, but is extended by the service-specific classes.
The Amazon API Key. This is inherited by all service-specific classes.
The Amazon API Secret Key. This is inherited by all service-specific classes.
The Amazon Account ID, sans hyphens. This is inherited by all service-specific classes.
The Amazon Associates ID. This is inherited by all service-specific classes.
Handle for the utility functions. This is inherited by all service-specific classes.
An identifier for the current AWS service. This is inherited by all service-specific classes.
The supported API version. This is inherited by all service-specific classes.
The default class to use for Utilities (defaults to CFUtilities). This is inherited by all service-specific classes.
The default class to use for HTTP Requests (defaults to RequestCore). This is inherited by all service-specific classes.
The default class to use for HTTP Responses (defaults to ResponseCore). This is inherited by all service-specific classes.
The number of seconds to adjust the request timestamp by (defaults to 0). This is inherited by all service-specific classes.
Whether SSL/HTTPS should be enabled by default. This is inherited by all service-specific classes.
Sets the proxy to use for connecting. This is inherited by all service-specific classes.
Stores the Amazon DevPay tokens to use, if any. This is inherited by all service-specific classes.
Stores the alternate hostname to use, if any. This is inherited by all service-specific classes.
public static function autoloader( $class )
Automatically load classes that aren’t included.
public static
| class_name | string (Required) The classname to load. |
void
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.
public
| key | string (Optional) Your Amazon API Key. If blank, it will look for the AWS_KEY constant. |
| secret_key | string (Optional) Your Amazon API Secret Key. If blank, it will look for the AWS_SECRET_KEY constant. |
| account_id | string (Optional) Your Amazon account ID without the hyphens. Required for EC2. If blank, it will look for the AWS_ACCOUNT_ID constant. |
| assoc_id | string (Optional) Your Amazon Associates ID. Required for AAWS. If blank, it will look for the AWS_ASSOC_ID constant. |
boolean FALSE if no valid values are set, otherwise true.
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().
public
| seconds | integer (Required) The number of seconds to adjust the sent timestamp by. |
void
<?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) */ ?>
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().
public
| proxy | string (Required) Accepts proxy credentials in the following format: proxy://user:pass@hostname:port |
void
<?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"*/
?>
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().
public
| hostname | string (Required) The alternate hostname to use in place of the default one. Useful for API-compatible applications living on different hostnames. |
void
<?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"
*/
?>
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().
public
void
<?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) */ ?>
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().
public
| class | string (Optional) The name of the new class to use for this functionality. Defaults to the default class. |
void
<?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)
*/
?>
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().
public
| class | string (Optional) The name of the new class to use for this functionality. Defaults to the default class. |
void
<?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"
*/
?>
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().
public
| class | string (Optional) The name of the new class to use for this functionality. Defaults to the default class. |
void
<?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"
*/
?>
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.
public
| action | string (Required) Indicates the action to perform. |
| opt | array (Optional) Associative array of parameters for authenticating. See the individual methods for allowed keys. |
| domain | string (Optional) The URL of the queue to perform the action on. |
| message | string (Optional) This parameter is only used by the send_message() method. |
ResponseCore object
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().
public
| method | string (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. |
| location | string (Required) The location to store the cache object in. This may vary by cache method. See below. |
| expires | integer (Required) The number of seconds until a cache object is considered stale. |
| params | array (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. |
| gzip | boolean (Optional) Whether data should be gzipped before being stored. Defaults to true. |
| File | Local file system paths such as ./cache (relative) or /tmp/cache/cloudfusion (absolute). Location must be server-writable. |
| APC | Pass in ‘apc’ to use this lightweight cache. You must have the APC extension installed. http://php.net/apc |
| XCache | Pass in ‘xcache’ to use this lightweight cache. You must have the XCache extension installed. http://xcache.lighttpd.net/ |
| Memcached | Pass 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. |
| PDO | A 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. |
ResponseCore object
<?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)
*/
?> <?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)
*/
?> <?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)
*/
?> <?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)
*/
?> <?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) */ ?>
<?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) */ ?>
public function delete_cache_response( $method, $location, $params = null )
Deletes a cached ResponseCore object using the preferred caching method.
public
| method | string (Required) The same method you used while caching initially. |
| location | string (Required) The same location you used while caching initially. |
| params | array (Optional) The same parameters that you used while caching initially. |
| File | Local file system paths such as ./cache (relative) or /tmp/cache/tarzan (absolute). Location must be server-writable. |
| APC | Pass in ‘apc’ to use this lightweight cache. You must have the APC extension installed. http://php.net/apc |
| XCache | Pass in ‘xcache’ to use this lightweight cache. You must have the XCache extension installed. http://xcache.lighttpd.net/ |
| Memcached | Pass 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. |
| PDO | A 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. |
boolean TRUE if cached object exists and is successfully deleted, otherwise FALSE
<?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)
*/
?> <?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)
*/
?> <?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)
*/
?> <?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)
*/
?>