HPCloud-PHP  1.2.0
PHP bindings for HPCloud and OpenStack services.
 All Classes Namespaces Files Functions Variables Pages
Bootstrap Class Reference

Bootstrapping services. More...

Static Public Member Functions

static useAutoloader ()
 Add the autoloader to PHP's autoloader list.
static useStreamWrappers ()
 Register stream wrappers for HPCloud.
static setConfiguration ($array)
 Set configuration directives for HPCloud.
static autoload ($klass)
 HPCloud autoloader.
static config ($name=NULL, $default=NULL)
 Get a configuration option.
static hasConfig ($name)
 Check whether the given configuration option is set.
static identity ($force=FALSE)
 Get a HPCloud::Services::IdentityService object from the bootstrap config.

Static Public Attributes

static $basedir = __DIR__
 The directory where HPCloud is located.
static $config
static $identity = NULL

Detailed Description

Bootstrapping services.

There is no requirement that this class be used. HPCloud is built to be flexible, and any individual component can be used directly, with one caveat: No explicit require or include calls are made. See the "autoloaders" discussion below.

This class provides the following services:

  • Configuration: "global" settings are set here. See the setConfiguration() method to see how they can be set, and the config() and hasConfig() methods to see how configuration might be checked.
  • Stream Wrappers: This class can initialize a set of stream wrappers which will make certain HPCloud services available through the core PHP stream support.
  • Autoloader: It provides a special-purpose autoloader that can load the HPCloud classes, but which will not interfere with other autoloading facilities.

Configuration

Configuration directives can be merged into the existing confiuration using the setConfiguration method.

<?php
$config = array(
// Use the faster and better CURL transport.
'transport' => '\HPCloud\Transport\CURLTransport',
// Set the HTTP max wait time to 500.
'transport.timeout' => 500,
);
// Check and get params.
if (Bootstrap::hasConf('transport.timeout') {
$to = Bootstrap::conf('transport.timeout');
}
// Or get a param with a default value:
$val = Bootstrap::conf('someval', 'default value');
// $val will be set to 'default value' because there
// is no 'someval' configuration param.
?>

AUTOLOADING

HPCloud comes with a built-in autoloader that can be called like this:

Attention
The structure of the HPCloud file hierarchy is PSR-0 compliant. This means that you can use any standard PSR-0 classloader to load all of the classes here.

That said, many projects rely upon packages to handle their own class loading. To provide this, this package contains a custom classloader that will load JUST the HPCloud classes. See the Bootstrap::useAutoloader() static method.

See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md

STREAM WRAPPERS

Stream wrappers allow you to use the built-in file manipulation functions in PHP to interact with other services. Specifically, the HPCloud stream wrappers allow you to use built-in file commands to access Object Storage (Swift) and other HPCloud services using commands like file_get_contents() and fopen().

It's awesome. Trust me.

Definition at line 117 of file Bootstrap.php.

Member Function Documentation

static autoload (   $klass)
static

HPCloud autoloader.

An implementation of a PHP autoload function. Use HPCloud::useAutoloader() if you want PHP to automatically load classes using this autoloader.

// Enable the autoloader.

This is a special-purpose autoloader for loading only the HPCloud classes. It will not attempt to autoload anything outside of the HPCloud namespace.

Because this is a special-purpose autoloader, it should be safe to use with other special-purpose autoloaders (and also projects that don't rely upon autoloaders).

Parameters
string$klassThe fully qualified name of the class to be autoloaded.

Definition at line 264 of file Bootstrap.php.

static config (   $name = NULL,
  $default = NULL 
)
static

Get a configuration option.

Get a configuration option by name, with an optional default.

Parameters
string$nameThe name of the configuration option to get.
mixed$defaultThe default value to return if the name is not found.
Return values
mixed
Returns
mixed The value, if found; or the default, if set; or NULL.

Definition at line 304 of file Bootstrap.php.

References $name.

Referenced by PHPStreamTransport\buildStreamContext(), and CURLTransport\handleDoRequest().

static hasConfig (   $name)
static

Check whether the given configuration option is set.

if (Bootstrap::hasConfig('transport')) {
syslog(LOG_INFO, 'An alternate transport is supplied.');
}
Parameters
string$nameThe name of the item to check for.
Return values
boolean
Returns
boolean TRUE if the named option is set, FALSE otherwise. Note that the value may be falsey (FALSE, 0, etc.), but if the value is NULL, this will return false.

Definition at line 337 of file Bootstrap.php.

References $name.

Referenced by PHPStreamTransport\buildStreamContext(), PHPStreamTransport\doRequest(), and CURLTransport\handleDoRequest().

static identity (   $force = FALSE)
static

Get a HPCloud::Services::IdentityService object from the bootstrap config.

A factory helper function that uses the bootstrap configuration to create a ready to use HPCloud::Services::IdentityService object.

Parameters
bool$forceWhether to force the generation of a new object even if one is already cached.
Return values
HPCloud::Services::IdentityService
Returns
\:IdentityService An authenticated ready to use HPCloud::Services::IdentityService object.
Exceptions
HPCloud::ExceptionWhen the needed configuration to authenticate is not available.

Definition at line 356 of file Bootstrap.php.

References $account.

static setConfiguration (   $array)
static

Set configuration directives for HPCloud.

This merges the provided associative array into the existing configuration parameters (Bootstrap::$config).

All of the HPCloud classes share the same configuration. This ensures that a stable runtime environment is maintained.

Common configuration directives:

  • 'transport': The namespaced classname for the transport that should be used. Example:
    \HPCloud\Transport\CURLTransport
  • 'transport.debug': The integer 1 for enabling debug, 0 for disabling. Enabling will turn on verbose debugging output for any transport that supports it.
  • 'transport.timeout': An integer value indicating how long the transport layer should wait for an HTTP request. A transport MAY ignore this parameter, but the ones included with the library honor it.
  • 'transport.ssl.verify': Set this to FALSE to turn off SSL certificate verification. This is NOT recommended, but is sometimes necessary for certain proxy configurations.
  • 'account' and 'secret'
  • 'username' and 'password'
  • 'tenantid'
  • 'endpoint': The full URL to identity services. This is used by stream wrappers.

The CURL wrapper supports proxy settings:

  • proxy: the proxy server URL (CURLOPT_PROXY)
  • proxy.userpwd: the proxy username:password (CURLOPT_PROXYUSERPWD)
  • proxy.auth: See CURLOPT_PROXYAUTH
  • proxy.port: The proxy port. (CURLOPT_PROXYPORT)
  • proxy.type: see CURLOPT_PROXYTYPE
  • proxy.tunnel: If this is set to TRUE, attempt to tunnel through the proxy. This is recommended when using a proxy. (CURLOPT_HTTPPROXYTUNNEL)
Parameters
array$arrayAn associative array of configuration directives.

Definition at line 236 of file Bootstrap.php.

static useAutoloader ( )
static

Add the autoloader to PHP's autoloader list.

This will add the internal special-purpose autoloader to the list of autoloaders that PHP will leverage to resolve class paths.

Because HPCloud is PSR-0 compliant, any full PSR-0 classloader should be capable of loading these classes witout issue. You may prefer to use a standard PSR-0 loader instead of this one.

See Also
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md

Definition at line 154 of file Bootstrap.php.

static useStreamWrappers ( )
static

Register stream wrappers for HPCloud.

This register the ObjectStorage stream wrappers, which allow you to access ObjectStorage through standard file access mechanisms.

// Enable stream wrapper.
// Create a context resource.
$cxt = stream_context_create(array(
'tenantid' => '12de21',
'account' => '123454321',
'secret' => 'f78saf7hhlll',
'endpoint' => 'https://identity.hpcloud.com' // <-- not real URL!
));
// Get the contents of a Swift object.
$content = file_get_contents('swift://public/notes.txt', 'r', FALSE, $cxt);

Definition at line 180 of file Bootstrap.php.

Member Data Documentation

$basedir = __DIR__
static

The directory where HPCloud is located.

Definition at line 122 of file Bootstrap.php.

$config
static
Initial value:
array(
'transport' => '\HPCloud\Transport\CURLTransport',
)

Definition at line 124 of file Bootstrap.php.

$identity = NULL
static

Definition at line 138 of file Bootstrap.php.


The documentation for this class was generated from the following file: