settings.
*
* @return $this A reference to the current instance.
*/
public function disable_ssl_verification($ssl_verification = false)
{
trigger_error('Disabling the verification of SSL certificates can lead to man-in-the-middle attacks. It is potentially unsafe and highly discouraged.', E_USER_WARNING);
$this->ssl_verification = $ssl_verification;
return $this;
}
/**
* Enables HTTP request/response header logging to `STDERR`.
*
* @param boolean $enabled (Optional) Whether or not to enable debug mode. Defaults to `true`.
* @return $this A reference to the current instance.
*/
public function enable_debug_mode($enabled = true)
{
$this->debug_mode = $enabled;
return $this;
}
/**
* Sets the maximum number of times to retry failed requests.
*
* @param integer $retries (Optional) The maximum number of times to retry failed requests. Defaults to `3`.
* @return $this A reference to the current instance.
*/
public function set_max_retries($retries = 3)
{
$this->max_retries = $retries;
return $this;
}
/**
* Set the caching configuration to use for response caching.
*
* @param string $location (Required) The location to store the cache object in. This may vary by cache method.
- File - The local file system paths such as
./cache (relative) or /tmp/cache/ (absolute). The location must be server-writable. - APC - Pass in
apc to use this lightweight cache. You must have the APC extension installed. - XCache - Pass in
xcache to use this lightweight cache. You must have the XCache extension installed. - 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/cache) or a standard DSN-style string (e.g. pdo.sqlite:/sqlite/cache.db). MUST be prefixed with pdo.. See CachePDO and PDO for more details.
* @param boolean $gzip (Optional) Whether or not data should be gzipped before being stored. A value of `true` will compress the contents before caching them. A value of `false` will leave the contents uncompressed. Defaults to `true`.
* @return $this A reference to the current instance.
*/
public function set_cache_config($location, $gzip = true)
{
// If we have an array, we're probably passing in Memcached servers and ports.
if (is_array($location))
{
$this->cache_class = 'CacheMC';
}
else
{
// I would expect locations like `/tmp/cache`, `pdo.mysql://user:pass@hostname:port`, `pdo.sqlite:memory:`, and `apc`.
$type = strtolower(substr($location, 0, 3));
switch ($type)
{
case 'apc':
$this->cache_class = 'CacheAPC';
break;
case 'xca': // First three letters of `xcache`
$this->cache_class = 'CacheXCache';
break;
case 'pdo':
$this->cache_class = 'CachePDO';
$location = substr($location, 4);
break;
default:
$this->cache_class = 'CacheFile';
break;
}
}
// Set the remaining cache information.
$this->cache_location = $location;
$this->cache_compress = $gzip;
return $this;
}
/**
* Register a callback function to execute whenever a data stream is read from using
* .
*
* The user-defined callback function should accept three arguments:
*
*
* $curl_handle - resource - Required - The cURL handle resource that represents the in-progress transfer.
* $file_handle - resource - Required - The file handle resource that represents the file on the local file system.
* $length - integer - Required - The length in kilobytes of the data chunk that was transferred.
*
*
* @param string|array|function $callback (Required) The callback function is called by , so you can pass the following values:
* - The name of a global function to execute, passed as a string.
* - A method to execute, passed as
array('ClassName', 'MethodName').
* - An anonymous function (PHP 5.3+).
* @return $this A reference to the current instance.
*/
public function register_streaming_read_callback($callback)
{
$this->registered_streaming_read_callback = $callback;
return $this;
}
/**
* Register a callback function to execute whenever a data stream is written to using
* .
*
* The user-defined callback function should accept two arguments:
*
*
* $curl_handle - resource - Required - The cURL handle resource that represents the in-progress transfer.
* $length - integer - Required - The length in kilobytes of the data chunk that was transferred.
*
*
* @param string|array|function $callback (Required) The callback function is called by , so you can pass the following values:
* - The name of a global function to execute, passed as a string.
* - A method to execute, passed as
array('ClassName', 'MethodName').
* - An anonymous function (PHP 5.3+).
* @return $this A reference to the current instance.
*/
public function register_streaming_write_callback($callback)
{
$this->registered_streaming_write_callback = $callback;
return $this;
}
/*%******************************************************************************************%*/
// SET CUSTOM CLASSES
/**
* Set a custom class for this functionality. Use this method when extending/overriding existing classes
* with new functionality.
*
* The replacement class must extend from .
*
* @param string $class (Optional) The name of the new class to use for this functionality.
* @return $this A reference to the current instance.
*/
public function set_utilities_class($class = 'CFUtilities')
{
$this->utilities_class = $class;
$this->util = new $this->utilities_class();
return $this;
}
/**
* Set a custom class for this functionality. Use this method when extending/overriding existing classes
* with new functionality.
*
* The replacement class must extend from .
*
* @param string $class (Optional) The name of the new class to use for this functionality.
* @param $this A reference to the current instance.
*/
public function set_request_class($class = 'CFRequest')
{
$this->request_class = $class;
return $this;
}
/**
* Set a custom class for this functionality. Use this method when extending/overriding existing classes
* with new functionality.
*
* The replacement class must extend from .
*
* @param string $class (Optional) The name of the new class to use for this functionality.
* @return $this A reference to the current instance.
*/
public function set_response_class($class = 'CFResponse')
{
$this->response_class = $class;
return $this;
}
/**
* Set a custom class for this functionality. Use this method when extending/overriding existing classes
* with new functionality.
*
* The replacement class must extend from .
*
* @param string $class (Optional) The name of the new class to use for this functionality.
* @return $this A reference to the current instance.
*/
public function set_parser_class($class = 'CFSimpleXML')
{
$this->parser_class = $class;
return $this;
}
/**
* Set a custom class for this functionality. Use this method when extending/overriding existing classes
* with new functionality.
*
* The replacement class must extend from .
*
* @param string $class (Optional) The name of the new class to use for this functionality.
* @return $this A reference to the current instance.
*/
public function set_batch_class($class = 'CFBatchRequest')
{
$this->batch_class = $class;
return $this;
}
/*%******************************************************************************************%*/
// AUTHENTICATION
/**
* Default, shared method for authenticating a connection to AWS. Overridden on a class-by-class basis
* as necessary.
*
* @param string $action (Required) Indicates the action to perform.
* @param array $opt (Optional) An associative array of parameters for authenticating. See the individual methods for allowed keys.
* @param string $domain (Optional) The URL of the queue to perform the action on.
* @param integer $signature_version (Optional) The signature version to use. Defaults to 2.
* @param integer $redirects (Do Not Use) Used internally by this function on occasions when Amazon S3 returns a redirect code and it needs to call itself recursively.
* @return CFResponse Object containing a parsed HTTP response.
*/
public function authenticate($action, $opt = null, $domain = null, $signature_version = 2, $redirects = 0)
{
// Handle nulls
if (is_null($signature_version))
{
$signature_version = 2;
}
$method_arguments = func_get_args();
$headers = array();
$signed_headers = array();
// Use the caching flow to determine if we need to do a round-trip to the server.
if ($this->use_cache_flow)
{
// Generate an identifier specific to this particular set of arguments.
$cache_id = $this->key . '_' . get_class($this) . '_' . $action . '_' . sha1(serialize($method_arguments));
// Instantiate the appropriate caching object.
$this->cache_object = new $this->cache_class($cache_id, $this->cache_location, $this->cache_expires, $this->cache_compress);
if ($this->delete_cache)
{
$this->use_cache_flow = false;
$this->delete_cache = false;
return $this->cache_object->delete();
}
// Invoke the cache callback function to determine whether to pull data from the cache or make a fresh request.
$data = $this->cache_object->response_manager(array($this, 'cache_callback'), $method_arguments);
// Parse the XML body
$data = $this->parse_callback($data);
// End!
return $data;
}
$return_curl_handle = false;
$x_amz_target = null;
// Do we have a custom resource prefix?
if ($this->resource_prefix)
{
$domain .= $this->resource_prefix;
}
// Determine signing values
$current_time = time() + $this->adjust_offset;
$date = gmdate(CFUtilities::DATE_FORMAT_RFC2616, $current_time);
$timestamp = gmdate(CFUtilities::DATE_FORMAT_ISO8601, $current_time);
$nonce = $this->util->generate_guid();
// Do we have an authentication token?
if ($this->auth_token)
{
$headers['X-Amz-Security-Token'] = $this->auth_token;
$query['SecurityToken'] = $this->auth_token;
}
// Manage the key-value pairs that are used in the query.
if (stripos($action, 'x-amz-target') !== false)
{
$x_amz_target = trim(str_ireplace('x-amz-target:', '', $action));
}
else
{
$query['Action'] = $action;
}
// Only add it if it exists.
if ($this->api_version)
{
$query['Version'] = $this->api_version;
}
// Only Signature v2
if ($signature_version === 2)
{
$query['AWSAccessKeyId'] = $this->key;
$query['SignatureMethod'] = 'HmacSHA256';
$query['SignatureVersion'] = 2;
$query['Timestamp'] = $timestamp;
}
$curlopts = array();
// Set custom CURLOPT settings
if (is_array($opt) && isset($opt['curlopts']))
{
$curlopts = $opt['curlopts'];
unset($opt['curlopts']);
}
// Merge in any options that were passed in
if (is_array($opt))
{
$query = array_merge($query, $opt);
}
$return_curl_handle = isset($query['returnCurlHandle']) ? $query['returnCurlHandle'] : false;
unset($query['returnCurlHandle']);
// Do a case-sensitive, natural order sort on the array keys.
uksort($query, 'strcmp');
// Normalize JSON input
if (isset($query['body']) && $query['body'] === '[]')
{
$query['body'] = '{}';
}
if ($this->use_aws_query)
{
// Create the string that needs to be hashed.
$canonical_query_string = $this->util->to_signable_string($query);
}
else
{
// Create the string that needs to be hashed.
$canonical_query_string = $this->util->encode_signature2($query['body']);
}
// Remove the default scheme from the domain.
$domain = str_replace(array('http://', 'https://'), '', $domain);
// Parse our request.
$parsed_url = parse_url('http://' . $domain);
// Set the proper host header.
if (isset($parsed_url['port']) && (integer) $parsed_url['port'] !== 80 && (integer) $parsed_url['port'] !== 443)
{
$host_header = strtolower($parsed_url['host']) . ':' . $parsed_url['port'];
}
else
{
$host_header = strtolower($parsed_url['host']);
}
// Set the proper request URI.
$request_uri = isset($parsed_url['path']) ? $parsed_url['path'] : '/';
if ($signature_version === 2)
{
// Prepare the string to sign
$string_to_sign = "POST\n$host_header\n$request_uri\n$canonical_query_string";
// Hash the AWS secret key and generate a signature for the request.
$query['Signature'] = base64_encode(hash_hmac('sha256', $string_to_sign, $this->secret_key, true));
}
// Generate the querystring from $query
$querystring = $this->util->to_query_string($query);
// Gather information to pass along to other classes.
$helpers = array(
'utilities' => $this->utilities_class,
'request' => $this->request_class,
'response' => $this->response_class,
);
// Compose the request.
$request_url = ($this->use_ssl ? 'https://' : 'http://') . $domain;
$request_url .= !isset($parsed_url['path']) ? '/' : '';
// Instantiate the request class
$request = new $this->request_class($request_url, $this->proxy, $helpers);
$request->set_method('POST');
$request->set_body($querystring);
$headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';
// Signing using X-Amz-Target is handled differently.
if ($signature_version === 3 && $x_amz_target)
{
$headers['X-Amz-Target'] = $x_amz_target;
$headers['Content-Type'] = 'application/json; amzn-1.0';
$headers['Content-Encoding'] = 'amz-1.0';
$request->set_body($query['body']);
$querystring = $query['body'];
}
// Pass along registered stream callbacks
if ($this->registered_streaming_read_callback)
{
$request->register_streaming_read_callback($this->registered_streaming_read_callback);
}
if ($this->registered_streaming_write_callback)
{
$request->register_streaming_write_callback($this->registered_streaming_write_callback);
}
// Add authentication headers
if ($signature_version === 3)
{
$headers['X-Amz-Nonce'] = $nonce;
$headers['Date'] = $date;
$headers['Content-Length'] = strlen($querystring);
$headers['Content-MD5'] = $this->util->hex_to_base64(md5($querystring));
$headers['Host'] = $host_header;
}
// Sort headers
uksort($headers, 'strnatcasecmp');
if ($signature_version === 3 && $this->use_ssl)
{
// Prepare the string to sign (HTTPS)
$string_to_sign = $date . $nonce;
}
elseif ($signature_version === 3 && !$this->use_ssl)
{
// Prepare the string to sign (HTTP)
$string_to_sign = "POST\n$request_uri\n\n";
}
// Add headers to request and compute the string to sign
foreach ($headers as $header_key => $header_value)
{
// Strip linebreaks from header values as they're illegal and can allow for security issues
$header_value = str_replace(array("\r", "\n"), '', $header_value);
// Add the header if it has a value
if ($header_value !== '')
{
$request->add_header($header_key, $header_value);
}
// Signature v3 over HTTP
if ($signature_version === 3 && !$this->use_ssl)
{
// Generate the string to sign
if (
substr(strtolower($header_key), 0, 8) === 'content-' ||
strtolower($header_key) === 'date' ||
strtolower($header_key) === 'expires' ||
strtolower($header_key) === 'host' ||
substr(strtolower($header_key), 0, 6) === 'x-amz-'
)
{
$string_to_sign .= strtolower($header_key) . ':' . $header_value . "\n";
$signed_headers[] = $header_key;
}
}
}
if ($signature_version === 3)
{
if (!$this->use_ssl)
{
$string_to_sign .= "\n";
if (isset($query['body']) && $query['body'] !== '')
{
$string_to_sign .= $query['body'];
}
// Convert from string-to-sign to bytes-to-sign
$bytes_to_sign = hash('sha256', $string_to_sign, true);
// Hash the AWS secret key and generate a signature for the request.
$signature = base64_encode(hash_hmac('sha256', $bytes_to_sign, $this->secret_key, true));
}
else
{
// Hash the AWS secret key and generate a signature for the request.
$signature = base64_encode(hash_hmac('sha256', $string_to_sign, $this->secret_key, true));
}
$headers['X-Amzn-Authorization'] = 'AWS3' . ($this->use_ssl ? '-HTTPS' : '')
. ' AWSAccessKeyId=' . $this->key
. ',Algorithm=HmacSHA256'
. ',SignedHeaders=' . implode(';', $signed_headers)
. ',Signature=' . $signature;
$request->add_header('X-Amzn-Authorization', $headers['X-Amzn-Authorization']);
}
// Update RequestCore settings
$request->request_class = $this->request_class;
$request->response_class = $this->response_class;
$request->ssl_verification = $this->ssl_verification;
// Debug mode
if ($this->debug_mode)
{
$request->debug_mode = $this->debug_mode;
}
if (count($curlopts))
{
$request->set_curlopts($curlopts);
}
// Manage the (newer) batch request API or the (older) returnCurlHandle setting.
if ($this->use_batch_flow)
{
$handle = $request->prep_request();
$this->batch_object->add($handle);
$this->use_batch_flow = false;
return $handle;
}
elseif ($return_curl_handle)
{
return $request->prep_request();
}
// Send!
$request->send_request();
$request_headers = $headers;
// Prepare the response.
$headers = $request->get_response_header();
$headers['x-aws-stringtosign'] = $string_to_sign;
$headers['x-aws-request-headers'] = $request_headers;
$headers['x-aws-body'] = $querystring;
$data = new $this->response_class($headers, $this->parse_callback($request->get_response_body(), $headers), $request->get_response_code());
// Was it Amazon's fault the request failed? Retry the request until we reach $max_retries.
if ((integer) $request->get_response_code() === 500 || (integer) $request->get_response_code() === 503)
{
if ($redirects <= $this->max_retries)
{
// Exponential backoff
$delay = (integer) (pow(4, $redirects) * 100000);
usleep($delay);
$data = $this->authenticate($action, $opt, $domain, $signature_version, ++$redirects);
}
}
return $data;
}
/*%******************************************************************************************%*/
// BATCH REQUEST LAYER
/**
* Specifies that the intended request should be queued for a later batch request.
*
* @param CFBatchRequest $queue (Optional) The instance to use for managing batch requests. If not available, it generates a new instance of .
* @return $this A reference to the current instance.
*/
public function batch(CFBatchRequest &$queue = null)
{
if ($queue)
{
$this->batch_object = $queue;
}
elseif ($this->internal_batch_object)
{
$this->batch_object = &$this->internal_batch_object;
}
else
{
$this->internal_batch_object = new $this->batch_class();
$this->batch_object = &$this->internal_batch_object;
}
$this->use_batch_flow = true;
return $this;
}
/**
* Executes the batch request queue by sending all queued requests.
*
* @param boolean $clear_after_send (Optional) Whether or not to clear the batch queue after sending a request. Defaults to `true`. Set this to `false` if you are caching batch responses and want to retrieve results later.
* @return array An array of objects.
*/
public function send($clear_after_send = true)
{
if ($this->use_batch_flow)
{
// When we send the request, disable batch flow.
$this->use_batch_flow = false;
// If we're not caching, simply send the request.
if (!$this->use_cache_flow)
{
$response = $this->batch_object->send();
$parsed_data = array_map(array($this, 'parse_callback'), $response);
$parsed_data = new CFArray($parsed_data);
// Clear the queue
if ($clear_after_send)
{
$this->batch_object->queue = array();
}
return $parsed_data;
}
// Generate an identifier specific to this particular set of arguments.
$cache_id = $this->key . '_' . get_class($this) . '_' . sha1(serialize($this->batch_object));
// Instantiate the appropriate caching object.
$this->cache_object = new $this->cache_class($cache_id, $this->cache_location, $this->cache_expires, $this->cache_compress);
if ($this->delete_cache)
{
$this->use_cache_flow = false;
$this->delete_cache = false;
return $this->cache_object->delete();
}
// Invoke the cache callback function to determine whether to pull data from the cache or make a fresh request.
$data_set = $this->cache_object->response_manager(array($this, 'cache_callback_batch'), array($this->batch_object));
$parsed_data = array_map(array($this, 'parse_callback'), $data_set);
$parsed_data = new CFArray($parsed_data);
// Clear the queue
if ($clear_after_send)
{
$this->batch_object->queue = array();
}
// End!
return $parsed_data;
}
// Load the class
$null = new CFBatchRequest();
unset($null);
throw new CFBatchRequest_Exception('You must use $object->batch()->send()');
}
/**
* Parses a response body into a PHP object if appropriate.
*
* @param CFResponse|string $response (Required) The object to parse, or an XML string that would otherwise be a response body.
* @param string $content_type (Optional) The content-type to use when determining how to parse the content.
* @return CFResponse|string A parsed object, or parsed XML.
*/
public function parse_callback($response, $headers = null)
{
// Shorten this so we have a (mostly) single code path
if (isset($response->body))
{
if (is_string($response->body))
{
$body = $response->body;
}
else
{
return $response;
}
}
elseif (is_string($response))
{
$body = $response;
}
else
{
return $response;
}
// Decompress gzipped content
if (isset($headers['content-encoding']))
{
switch (strtolower(trim($headers['content-encoding'], "\x09\x0A\x0D\x20")))
{
case 'gzip':
case 'x-gzip':
if (strpos($headers['_info']['url'], 'monitoring.') !== false)
{
// CloudWatch incorrectly uses the deflate algorithm when they say gzip.
if (($uncompressed = gzuncompress($body)) !== false)
{
$body = $uncompressed;
}
elseif (($uncompressed = gzinflate($body)) !== false)
{
$body = $uncompressed;
}
break;
}
else
{
// Everyone else uses gzip correctly.
$decoder = new CFGzipDecode($body);
if ($decoder->parse())
{
$body = $decoder->data;
}
break;
}
case 'deflate':
if (strpos($headers['_info']['url'], 'monitoring.') !== false)
{
// CloudWatchWatch incorrectly does nothing when they say deflate.
break; //(6/12/2023 Changed from continue to break to prevent PHP error/warning for required following optional)
}
else
{
// Everyone else uses deflate correctly.
if (($uncompressed = gzuncompress($body)) !== false)
{
$body = $uncompressed;
}
elseif (($uncompressed = gzinflate($body)) !== false)
{
$body = $uncompressed;
}
}
break;
case 'br':
if (strpos($headers['_info']['url'], 'monitoring.') !== false)
{
// CloudWatchWatch incorrectly does nothing when they say br.
break; //(6/12/2023 Changed from continue to break to prevent PHP error/warning for required following optional)
}
else
{
// Everyone else uses br correctly.
if (($uncompressed = brotli_uncompress($body)) !== false)
{
$body = $uncompressed;
}
}
break;
}
}
// Look for XML cues
if (
(isset($headers['content-type']) && ($headers['content-type'] === 'text/xml' || $headers['content-type'] === 'application/xml')) || // We know it's XML
(!isset($headers['content-type']) && (stripos($body, '') === 0) || preg_match('/^<(\w*) xmlns="http(s?):\/\/(\w*).amazon(aws)?.com/im', $body)) // Sniff for XML
)
{
// Strip the default XML namespace to simplify XPath expressions
$body = str_replace("xmlns=", "ns=", $body);
// Parse the XML body
$body = new $this->parser_class($body);
}
// Look for JSON cues
elseif (
(isset($headers['content-type']) && $headers['content-type'] === 'application/json') || // We know it's JSON
(!isset($headers['content-type']) && $this->util->is_json($body)) // Sniff for JSON
)
{
// Normalize JSON to a CFSimpleXML object
$body = CFJSON::to_xml($body);
}
// Put the parsed data back where it goes
if (isset($response->body))
{
$response->body = $body;
}
else
{
$response = $body;
}
return $response;
}
/*%******************************************************************************************%*/
// CACHING LAYER
/**
* Specifies that the resulting object should be cached according to the settings from
* .
*
* @param string|integer $expires (Required) The time the cache is to expire. Accepts a number of seconds as an integer, or an amount of time, as a string, that is understood by (e.g. "1 hour").
* @param $this A reference to the current instance.
* @return $this
*/
public function cache($expires)
{
// Die if they haven't used set_cache_config().
if (!$this->cache_class)
{
throw new CFRuntime_Exception('Must call set_cache_config() before using cache()');
}
if (is_string($expires))
{
$expires = strtotime($expires);
$this->cache_expires = $expires - time();
}
elseif (is_int($expires))
{
$this->cache_expires = $expires;
}
$this->use_cache_flow = true;
return $this;
}
/**
* The callback function that is executed when the cache doesn't exist or has expired. The response of
* this method is cached. Accepts identical parameters as the method. Never call this
* method directly -- it is used internally by the caching system.
*
* @param string $action (Required) Indicates the action to perform.
* @param array $opt (Optional) An associative array of parameters for authenticating. See the individual methods for allowed keys.
* @param string $domain (Optional) The URL of the queue to perform the action on.
* @param integer $signature_version (Optional) The signature version to use. Defaults to 2.
* @return CFResponse A parsed HTTP response.
*/
public function cache_callback($action, $opt = null, $domain = null, $signature_version = 2)
{
// Disable the cache flow since it's already been handled.
$this->use_cache_flow = false;
// Make the request
$response = $this->authenticate($action, $opt, $domain, $signature_version);
// If this is an XML document, convert it back to a string.
if (isset($response->body) && ($response->body instanceof SimpleXMLElement))
{
$response->body = $response->body->asXML();
}
return $response;
}
/**
* Used for caching the results of a batch request. Never call this method directly; it is used
* internally by the caching system.
*
* @param CFBatchRequest $batch (Required) The batch request object to send.
* @return CFResponse A parsed HTTP response.
*/
public function cache_callback_batch(CFBatchRequest $batch)
{
return $batch->send();
}
/**
* Deletes a cached object using the specified cache storage type.
*
* @return boolean A value of `true` if cached object exists and is successfully deleted, otherwise `false`.
*/
public function delete_cache()
{
$this->use_cache_flow = true;
$this->delete_cache = true;
return $this;
}
}
/**
* Contains the functionality for auto-loading service classes.
*/
class CFLoader
{
/*%******************************************************************************************%*/
// AUTO-LOADER
/**
* Automatically load classes that aren't included.
*
* @param string $class (Required) The classname to load.
* @return void
*/
public static function autoloader($class)
{
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR;
// Amazon SDK classes
if (strstr($class, 'Amazon'))
{
$path .= 'services' . DIRECTORY_SEPARATOR . str_ireplace('Amazon', '', strtolower($class)) . '.class.php';
}
// Utility classes
elseif (strstr($class, 'CF'))
{
$path .= 'utilities' . DIRECTORY_SEPARATOR . str_ireplace('CF', '', strtolower($class)) . '.class.php';
}
// Load CacheCore
elseif (strstr($class, 'Cache'))
{
if (file_exists($ipath = 'lib' . DIRECTORY_SEPARATOR . 'cachecore' . DIRECTORY_SEPARATOR . 'icachecore.interface.php'))
{
require_once($ipath);
}
$path .= 'lib' . DIRECTORY_SEPARATOR . 'cachecore' . DIRECTORY_SEPARATOR . strtolower($class) . '.class.php';
}
// Load RequestCore
elseif (strstr($class, 'RequestCore') || strstr($class, 'ResponseCore'))
{
$path .= 'lib' . DIRECTORY_SEPARATOR . 'requestcore' . DIRECTORY_SEPARATOR . 'requestcore.class.php';
}
// Load Symfony YAML classes
elseif (strstr($class, 'sfYaml'))
{
$path .= 'lib' . DIRECTORY_SEPARATOR . 'yaml' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'sfYaml.php';
}
// Fall back to the 'extensions' directory.
elseif (defined('AWS_ENABLE_EXTENSIONS') && AWS_ENABLE_EXTENSIONS)
{
$path .= 'extensions' . DIRECTORY_SEPARATOR . strtolower($class) . '.class.php';
}
if (file_exists($path) && !is_dir($path))
{
require_once($path);
}
}
}
// Register the autoloader.
spl_autoload_register(array('CFLoader', 'autoloader'));