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

Provides stream wrapping for Swift. More...

Inheritance diagram for StreamWrapper:
StreamWrapperFS

Public Member Functions

 dir_closedir ()
 Close a directory.
 dir_opendir ($path, $options)
 Open a directory for reading.
 dir_readdir ()
 Read an entry from the directory.
 dir_rewinddir ()
 Rewind to the beginning of the listing.
 rename ($path_from, $path_to)
 Rename a swift object.
 stream_cast ($cast_as)
 Cast stream into a lower-level stream.
 stream_close ()
 Close a stream, writing if necessary.
 stream_eof ()
 Check whether the stream has reached its end.
 stream_flush ()
 Initiate saving data on the remote object storage.
 stream_open ($path, $mode, $options, &$opened_path)
 Open a stream resource.
 stream_read ($count)
 Read N bytes from the stream.
 stream_seek ($offset, $whence)
 Perform a seek.
 stream_set_option ($option, $arg1, $arg2)
 Set options on the underlying stream.
 stream_stat ()
 Perform stat()/lstat() operations.
 stream_tell ()
 Get the current position in the stream.
 stream_write ($data)
 Write data to stream.
 unlink ($path)
 Unlink a file.
 url_stat ($path, $flags)
 object ()
 Get the Object.
 objectStorage ()
 EXPERT: Get the ObjectStorage for this wrapper.
 token ()
 EXPERT: Get the auth token for this wrapper.
 serviceCatalog ()
 EXPERT: Get the service catalog (IdentityServices) for this wrapper.

Public Attributes

const DEFAULT_SCHEME = 'swift'
 $context
 The stream context.

Protected Member Functions

 writeRemote ()
 Write data to the remote object storage.
 generateStat ($object, $container, $size)
 Generate a reasonably accurate STAT array.
 setMode ($mode)
 Set the fopen mode.
 cxt ($name, $default=NULL)
 Get an item out of the context.
 parseUrl ($url)
 Parse a URL.
 initializeObjectStorage ()
 Based on the context, initialize the ObjectStorage.
 initializeCDN ($token, $catalog)
 Initialize CDN service.
 authenticate ()

Protected Attributes

 $contextArray = array()
 $schemeName = self::DEFAULT_SCHEME
 $authToken
 $isBinary = FALSE
 $isText = TRUE
 $isWriting = FALSE
 $isReading = FALSE
 $isTruncating = FALSE
 $isAppending = FALSE
 $noOverwrite = FALSE
 $createIfNotFound = TRUE
 $isNeverDirty = FALSE
 If this is TRUE, no data is ever sent to the remote server.
 $triggerErrors = FALSE
 $isDirty = FALSE
 Indicate whether the local differs from remote.
 $store
 Object storage instance.
 $container
 The Container.
 $obj
 The Object.
 $objStream
 The IO stream for the Object.
 $dirListing = array()
 Directory listing.
 $dirIndex = 0
 $dirPrefix = ''

Static Protected Attributes

static $serviceCatalogCache = array()
 Cache of auth token -> service catalog.

Detailed Description

Provides stream wrapping for Swift.

This provides a full stream wrapper to expose swift:// URLs to the PHP stream system.

Swift streams provide authenticated and priviledged access to the swift data store. These URLs are not generally used for granting unauthenticated access to files (which can be done using the HTTP stream wrapper – no need for swift-specific logic).

URL Structure

This takes URLs of the following form:

swift://CONTAINER/FILE

Example:

swift://public/example.txt

The example above would access the public container and attempt to retrieve the file named example.txt.

Slashes are legal in Swift filenames, so a pathlike URL can be constructed like this:

swift://public/path/like/file/name.txt

The above would attempt to find a file in object storage named path/like/file/name.txt.

A note on UTF-8 and URLs: PHP does not yet natively support many UTF-8 characters in URLs. Thus, you ought to rawurlencode() your container name and object name (path) if there is any possibility that it will contain UTF-8 characters.

Locking

This library does not support locking (e.g. flock()). This is because the OpenStack Object Storage implementation does not support locking. But there are a few related things you should keep in mind:

  • Working with a stream is essentially working with a COPY OF a remote file. Local locking is not an issue.
  • If you open two streams for the same object, you will be working with TWO COPIES of the object. This can, of course, lead to nasty race conditions if each copy is modified.

Usage

The principle purpose of this wrapper is to make it easy to access and manipulate objects on a remote object storage instance. Managing containers is a secondary concern (and can often better be managed using the HPCloud API). Consequently, almost all actions done through the stream wrapper are focused on objects, not containers, servers, etc.

Retrieving an Existing Object

Retrieving an object is done by opening a file handle to that object.

Writing an Object

Nothing is written to the remote storage until the file is closed. This keeps network traffic at a minimum, and respects the more-or-less stateless nature of ObjectStorage.

USING FILE/STREAM RESOURCES

In general, you should access files like this:

<?php
\HPCloud\Bootstrap::useStreamWrappers();
// Set up the context.
$context = stream_context_create(
array('swift' => array(
'account' => ACCOUNT_NUMBER,
'secret' => SECRET_KEY,
'tenantid' => TENANT_ID,
'tenantname' => TENANT_NAME, // Optional instead of tenantid.
'endpoint' => AUTH_ENDPOINT_URL,
)
)
);
// Open the file.
$handle = fopen('swift://mycontainer/myobject.txt', 'r+', FALSE, $context);
// You can get the entire file, or use fread() to loop through the file.
$contents = stream_get_contents($handle);
fclose($handle);
?>
Remarks
  • file_get_contents() works fine.
  • You can write to a stream, too. Nothing is pushed to the server until fflush() or fclose() is called.
  • Mode strings (w, r, w+, r+, c, c+, a, a+, x, x+) all work, though certain constraints are slightly relaxed to accomodate efficient local buffering.
  • Files are buffered locally.

USING FILE-LEVEL FUNCTIONS

PHP provides a number of file-level functions that stream wrappers can optionally support. Here are a few such functions:

  • file_exists()
  • is_readable()
  • stat()
  • filesize()
  • fileperms()

The HPCloud stream wrapper provides support for these file-level functions. But there are a few things you should know:

  • Each call to one of these functions generates at least one request. It may be as many as three:
    • An auth request
    • A request for the container (to get container permissions)
    • A request for the object
  • IMPORTANT: Unlike the fopen()/fclose()... functions NONE of these functions retrieves the body of the file. If you are working with large files, using these functions may be orders of magnitude faster than using fopen(), etc. (The crucial detail: These kick off a HEAD request, will fopen() does a GET request).
  • You must use Bootstrap::setConfiguration() to pass in all of the values you would normally pass into a stream context:
    • endpoint
    • account
    • secret
  • Most of the information from this family of calls can also be obtained using fstat(). If you were going to open a stream anyway, you might as well use fopen()/fstat().
  • stat() and fstat() fake the permissions and ownership as follows:
    • uid/gid are always sset to the current user. This basically assumes that if the current user can access the object, the current user has ownership over the file. As the OpenStack ACL system developers, this may change.
    • Mode is faked. Swift uses ACLs, not UNIX mode strings. So we fake the string:
      • 770: The ACL has the object marked as private.
      • 775: The ACL has the object marked as public.
      • ACLs are actually set on the container, so every file in a public container will return 775.
  • stat/fstat provide only one timestamp. Swift only tracks mtime, so mtime, atime, and ctime are all set to the last modified time.

DIRECTORIES

OpenStack Swift does not really have directories. Rather, it allows characters such as '/' to be used to designate namespaces on object names. (For simplicity, this library uses only '/' as a separator).

This allows for simulated directory listings. Requesting `scandir('swift://foo/bar/')` is really a request to "find all of the items in the 'foo' container whose names start with 'bar/'".

Because of this...

  • Directory reading functions like scandir(), opendir(), readdir() and so forth are supported.
  • Functions to create or remove directories (mkdir() and rmdir()) are meaningless, and thus not supported.

Swift still has support for "directory markers" (special zero-byte files that act like directories). However, since there are no standards for how said markers ought to be created, they are not supported by the stream wrapper.

As usual, the underlying HPCloud::Storage::ObjectStorage::Container class supports the full range of Swift features.

SUPPORTED CONTEXT PARAMETERS

This section details paramters that can be passed either through a stream context or through HPCloud::Bootstrap::setConfiguration().

Attention
PHP functions that do not allow you to pass a context may still be supported here IF you have set options using Bootstrap::setConfiguration().

You are required to pass in authentication information. This comes in one of three forms:

  1. API keys: acccount, secret, tenantid, endpoint
  2. User login: username, password, tenantid, endpoint
  3. Existing (valid) token: token, swift_endpoint
Attention
As of 1.0.0-beta6, you may use tenantname instead of tenantid.

The third method (token) can be used when the application has already authenticated. In this case, a token has been generated and assigned to an account and tenant.

The following parameters may be set either in the stream context or through HPCloud::Bootstrap::setConfiguration():

  • token: An auth token. If this is supplied, authentication is skipped and this token is used. NOTE: You MUST set swift_endpoint if using this option.
  • swift_endpoint: The URL to the swift instance. This is only necessary if 'token' is set. Otherwise it is ignored.
  • username: A username. MUST be accompanied by 'password' and 'tenantid' (or 'tenantname').
  • password: A password. MUST be accompanied by 'username' and 'tenantid' (or 'tenantname').
  • account: An account ID. MUST be accompanied by a 'secret' and 'tenantid' (or 'tenantname').
  • secret: A secret key. MUST be accompanied by an 'account' and 'tenantid' (or 'tenantname').
  • endpoint: The URL to the authentication endpoint. Necessary if you are not using a 'token' and 'swift_endpoint'.
  • use_swift_auth: If this is set to TRUE, it will force the app to use the deprecated swiftAuth instead of IdentityServices authentication. In general, you should avoid using this.
  • content_type: This is effective only when writing files. It will set the Content-Type of the file during upload.
  • use_cdn: If this is set to TRUE, then whenever possible assets will be loaded from CDN instead of from the object store. The following conditions must obtain for this to work:
    • The container must allow public reading (ACL)
    • The container must have CDN enabled
    • The CDN container must be active ("cdn-enabled")
    • Authentication info must be accessible to the stream wrapper.
  • cdn_require_ssl: If this is set to FALSE, then CDN-based requests may use plain HTTP instead of HTTPS. This will spead up CDN fetches at the cost of security.
  • tenantid: The tenant ID for the services you will use. (An account may have multiple tenancies associated.)
  • tenantname: The tenant name for the services you will use. You may use this in lieu of tenant ID.
Attention
ADVANCED: You can also pass an HPCloud::Storage::CDN object in use_cdn instead of a boolean.
See Also
http://us3.php.net/manual/en/class.streamwrapper.php
Todo:
The service catalog should be cached in the context like the token so that it can be retrieved later.

Definition at line 272 of file StreamWrapper.php.

Member Function Documentation

authenticate ( )
protected
cxt (   $name,
  $default = NULL 
)
protected

Get an item out of the context.

Todo:
Should there be an option to NOT query the Bootstrap::conf()?
Parameters
string$nameThe name to look up. First look it up in the context, then look it up in the Bootstrap config.
mixed$defaultThe default value to return if no config param was found.
Return values
mixed
Returns
mixed The discovered result, or $default if specified, or NULL if no $default is specified.

Definition at line 1426 of file StreamWrapper.php.

References $cxt, and $name.

Referenced by StreamWrapper\authenticate(), StreamWrapperFS\fakeStat(), StreamWrapper\initializeCDN(), StreamWrapper\initializeObjectStorage(), StreamWrapperFS\mkdir(), StreamWrapper\stream_open(), StreamWrapperFS\url_stat(), and StreamWrapper\writeRemote().

dir_closedir ( )

Close a directory.

This closes a directory handle, freeing up the resources.

<?php
// Assuming a valid context in $cxt...
// Get the container as if it were a directory.
$dir = opendir('swift://mycontainer', $cxt);
// Do something with $dir
closedir($dir);
?>

NB: Some versions of PHP 5.3 don't clear all buffers when closing, and the handle can occasionally remain accessible for some period of time.

Definition at line 377 of file StreamWrapper.php.

dir_opendir (   $path,
  $options 
)

Open a directory for reading.

<?php
// Assuming a valid context in $cxt...
// Get the container as if it were a directory.
$dir = opendir('swift://mycontainer', $cxt);
// Do something with $dir
closedir($dir);
?>

See opendir() and scandir().

Parameters
string$pathThe URL to open.
int$optionsUnused.
Return values
boolean
Returns
boolean TRUE if the directory is opened, FALSE otherwise.

Definition at line 413 of file StreamWrapper.php.

References $container, ObjectStorage\$url, StreamWrapper\initializeObjectStorage(), and StreamWrapper\parseUrl().

dir_readdir ( )

Read an entry from the directory.

This gets a single line from the directory.

<?php
// Assuming a valid context in $cxt...
// Get the container as if it were a directory.
$dir = opendir('swift://mycontainer', $cxt);
while (($entry = readdir($dir)) !== FALSE) {
print $entry . PHP_EOL;
}
closedir($dir);
?>
Return values
string
Returns
string The name of the resource or FALSE when the directory has no more entries.

Definition at line 470 of file StreamWrapper.php.

dir_rewinddir ( )

Rewind to the beginning of the listing.

This repositions the read pointer at the first entry in the directory.

<?php
// Assuming a valid context in $cxt...
// Get the container as if it were a directory.
$dir = opendir('swift://mycontainer', $cxt);
while (($entry = readdir($dir)) !== FALSE) {
print $entry . PHP_EOL;
}
rewinddir($dir);
$first = readdir($dir);
closedir($dir);
?>

Definition at line 519 of file StreamWrapper.php.

generateStat (   $object,
  $container,
  $size 
)
protected

Generate a reasonably accurate STAT array.

Notes on mode:

  • All modes are of the (octal) form 100XXX, where XXX is replaced by the permission string. Thus, this always reports that the type is "file" (100).
  • Currently, only two permission sets are generated:

Notes on mtime/atime/ctime:

  • For whatever reason, Swift only stores one timestamp. We use that for mtime, atime, and ctime.

Notes on size:

  • Size must be calculated externally, as it will sometimes be the remote's Content-Length, and it will sometimes be the cached stat['size'] for the underlying buffer.

Definition at line 1271 of file StreamWrapper.php.

References $container, and $object.

Referenced by StreamWrapper\stream_stat(), and StreamWrapper\url_stat().

initializeCDN (   $token,
  $catalog 
)
protected

Initialize CDN service.

When the use_cdn parameter is passed into the context, we try to use a CDN service wherever possible.

If use_cdn is set to TRUE, we try to create a new CDN object. This will require a service catalog.

When use_cdn is set to TRUE, the wrapper tries to use CDN service. In such cases, we need a handle to the CDN object. This initializes that handle, which can later be used to get other information.

Also note that CDN's default behavior is to fetch over SSL CDN. To disable this, set 'cdn_require_ssl' to FALSE.

Definition at line 1611 of file StreamWrapper.php.

References $catalog, ObjectStorage\$token, StreamWrapper\authenticate(), StreamWrapper\cxt(), and ObjectStorage\newFromServiceCatalog().

Referenced by StreamWrapper\initializeObjectStorage().

initializeObjectStorage ( )
protected

Based on the context, initialize the ObjectStorage.

The following parameters may be set either in the stream context or through HPCloud::Bootstrap::setConfiguration():

  • token: An auth token. If this is supplied, authentication is skipped and this token is used. NOTE: You MUST set swift_endpoint if using this option.
  • swift_endpoint: The URL to the swift instance. This is only necessary if 'token' is set. Otherwise it is ignored.
  • username: A username. MUST be accompanied by 'password' and 'tenantname'.
  • password: A password. MUST be accompanied by 'username' and 'tenantname'.
  • account: An account ID. MUST be accompanied by a 'secret' and 'tenantname'.
  • secret: A secret key. MUST be accompanied by an 'account' and 'tenantname'.
  • endpoint: The URL to the authentication endpoint. Necessary if you are not using a 'token' and 'swift_endpoint'.
  • use_swift_auth: If this is set to TRUE, it will force the app to use the deprecated swiftAuth instead of IdentityServices authentication. In general, you should avoid using this.

To find these params, the method first checks the supplied context. If the key is not found there, it checks the Bootstrap::conf().

This should be rewritten to use ObjectStorage::newFromServiceCatalog().

Definition at line 1519 of file StreamWrapper.php.

References $account, $endpoint, $key, $tenantId, ObjectStorage\$token, StreamWrapper\authenticate(), StreamWrapper\cxt(), StreamWrapper\initializeCDN(), ObjectStorage\newFromServiceCatalog(), and ObjectStorage\newFromSwiftAuth().

Referenced by StreamWrapper\dir_opendir(), StreamWrapper\rename(), StreamWrapper\stream_open(), StreamWrapperFS\testDirectoryExists(), StreamWrapper\unlink(), and StreamWrapper\url_stat().

object ( )

Get the Object.

This provides low-level access to the PHCloud::Storage::ObjectStorage::Object instance in which the content is stored.

Accessing the object's payload (Object::content()) is strongly discouraged, as it will modify the pointers in the stream that the stream wrapper is using.

HOWEVER, accessing the Object's metadata properties, content type, and so on is okay. Changes to this data will be written on the next flush, provided that the file stream data has also been changed.

To access this:

<?php
$handle = fopen('swift://container/test.txt', 'rb', $cxt);
$md = stream_get_meta_data($handle);
$obj = $md['wrapper_data']->object();
?>

Definition at line 1212 of file StreamWrapper.php.

objectStorage ( )

EXPERT: Get the ObjectStorage for this wrapper.

Return values
objectHPCloud::ObjectStorage An ObjectStorage object.
See Also
object()

Definition at line 1223 of file StreamWrapper.php.

References $store.

parseUrl (   $url)
protected

Parse a URL.

In order to provide full UTF-8 support, URLs must be rawurlencoded before they are passed into the stream wrapper.

This parses the URL and urldecodes the container name and the object name.

Parameters
string$urlA Swift URL.
Return values
array
Returns
array An array as documented in parse_url().

Definition at line 1472 of file StreamWrapper.php.

References $key, and ObjectStorage\$url.

Referenced by StreamWrapper\dir_opendir(), StreamWrapper\rename(), StreamWrapper\stream_open(), StreamWrapperFS\testDirectoryExists(), StreamWrapper\unlink(), and StreamWrapper\url_stat().

rename (   $path_from,
  $path_to 
)

Rename a swift object.

This works by copying the object (metadata) and then removing the original version.

This DOES support cross-container renaming.

See Container::copy().

<?php
'tenantname' => 'foo@example.com',
// 'tenantid' => '1234', // You can use this instead of tenantname
'account' => '1234',
'secret' => '4321',
'endpoint' => 'https://auth.example.com',
));
$from = 'swift://containerOne/file.txt';
$to = 'swift://containerTwo/file.txt';
// Rename can also take a context as a third param.
rename($from, $to);
?>
Parameters
string$path_fromA swift URL that exists on the remote.
string$path_toA swift URL to another path.
Return values
boolean
Returns
boolean TRUE on success, FALSE otherwise.

Definition at line 570 of file StreamWrapper.php.

References $container, $object, StreamWrapper\initializeObjectStorage(), and StreamWrapper\parseUrl().

serviceCatalog ( )

EXPERT: Get the service catalog (IdentityServices) for this wrapper.

This is only available when a file is opened via fopen().

Return values
arrayA service catalog.
See Also
object()

Definition at line 1247 of file StreamWrapper.php.

References ObjectStorage\token().

setMode (   $mode)
protected

Set the fopen mode.

Parameters
string$modeThe mode string, e.g. r+ or wb.
Return values
HPCloud::Storage::ObjectStorage::StreamWrapper
Returns
$this so the method can be used in chaining.

Definition at line 1338 of file StreamWrapper.php.

Referenced by StreamWrapper\stream_open().

stream_cast (   $cast_as)

Cast stream into a lower-level stream.

This is used for stream_select() and perhaps others.Because it exposes the lower-level buffer objects, this function can have unexpected side effects.

Return values
resource
Returns
resource this returns the underlying stream.

Definition at line 618 of file StreamWrapper.php.

stream_close ( )

Close a stream, writing if necessary.

<?php
// Assuming $cxt has a valid context.
$file = fopen('swift://container/file.txt', 'r', FALSE, $cxt);
fclose($file);
?>

This will close the present stream. Importantly, this will also write to the remote object storage if any changes have been made locally.

See stream_open().

Definition at line 643 of file StreamWrapper.php.

References StreamWrapper\writeRemote().

stream_eof ( )

Check whether the stream has reached its end.

This checks whether the stream has reached the end of the object's contents.

Called when feof() is called on a stream.

See stream_seek().

Return values
boolean
Returns
boolean TRUE if it has reached the end, FALSE otherwise.

Definition at line 672 of file StreamWrapper.php.

stream_flush ( )

Initiate saving data on the remote object storage.

If the local copy of this object has been modified, it is written remotely.

Called when fflush() is called on a stream.

Definition at line 684 of file StreamWrapper.php.

References StreamWrapper\writeRemote().

stream_open (   $path,
  $mode,
  $options,
$opened_path 
)

Open a stream resource.

This opens a given stream resource and prepares it for reading or writing.

<?php
$cxt = stream_context_create(array(
'account' => '1bc123456',
'tenantid' => '987654321',
'secret' => 'eieio',
'endpoint' => 'https://auth.example.com',
));
?>
$file = fopen('swift://myContainer/myObject.csv', 'rb', FALSE, $cxt);
while ($bytes = fread($file, 8192)) {
print $bytes;
}
fclose($file);
?>

If a file is opened in write mode, its contents will be retrieved from the remote storage and cached locally for manipulation. If the file is opened in a write-only mode, the contents will be created locally and then pushed remotely as necessary.

During this operation, the remote host may need to be contacted for authentication as well as for file retrieval.

Parameters
string$pathThe URL to the resource. See the class description for details, but typically this expects URLs in the form swift://CONTAINER/OBJECT.
string$modeAny of the documented mode strings. See fopen(). For any file that is in a writing mode, the file will be saved remotely on flush or close. Note that there is an extra mode: 'nope'. It acts like 'c+' except that it is never written remotely. This is useful for debugging the stream locally without sending that data to object storage. (Note that data is still fetched – just never written.)
int$optionsAn OR'd list of options. Only STREAM_REPORT_ERRORS has any meaning to this wrapper, as it is not working with local files.
string$opened_pathThis is not used, as this wrapper deals only with remote objects.

Definition at line 782 of file StreamWrapper.php.

References ObjectStorage\$token, ObjectStorage\$url, ObjectStorage\container(), StreamWrapper\cxt(), StreamWrapper\initializeObjectStorage(), StreamWrapper\parseUrl(), and StreamWrapper\setMode().

stream_read (   $count)

Read N bytes from the stream.

This will read up to the requested number of bytes. Or, upon hitting the end of the file, it will return NULL.

See fread(), fgets(), and so on for examples.

<?php
$cxt = stream_context_create(array(
'tenantname' => 'me@example.com',
'username' => 'me@example.com',
'password' => 'secret',
'endpoint' => 'https://auth.example.com',
));
$content = file_get_contents('swift://public/myfile.txt', FALSE, $cxt);
?>
Parameters
int$countThe number of bytes to read (usually 8192).
Return values
string
Returns
string The data read.

Definition at line 980 of file StreamWrapper.php.

stream_seek (   $offset,
  $whence 
)

Perform a seek.

This is called whenever fseek() or rewind() is called on a Swift stream.

Attention
IMPORTANT: Unlike the PHP core, this library allows you to fseek() inside of a file opened in append mode ('a' or 'a+').

Definition at line 995 of file StreamWrapper.php.

stream_set_option (   $option,
  $arg1,
  $arg2 
)

Set options on the underlying stream.

The settings here do not trickle down to the network socket, which is left open for only a brief period of time. Instead, they impact the middle buffer stream, where the file is read and written to between flush/close operations. Thus, tuning these will not have any impact on network performance.

See stream_set_blocking(), stream_set_timeout(), and stream_write_buffer().

Definition at line 1014 of file StreamWrapper.php.

stream_stat ( )

Perform stat()/lstat() operations.

<?php
$file = fopen('swift://foo/bar', 'r+', FALSE, $cxt);
$stats = fstat($file);
?>

To use standard stat() on a Swift stream, you will need to set account information (tenant ID, account ID, secret, etc.) through HPCloud::Bootstrap::setConfiguration().

Return values
array
Returns
array The stats array.

Definition at line 1046 of file StreamWrapper.php.

References ObjectStorage\container(), and StreamWrapper\generateStat().

stream_tell ( )

Get the current position in the stream.

See ftell() and fseek().

Return values
int
Returns
int The current position in the stream.

Definition at line 1065 of file StreamWrapper.php.

stream_write (   $data)

Write data to stream.

This writes data to the local stream buffer. Data is not pushed remotely until stream_close() or stream_flush() is called.

Parameters
string$dataData to write to the stream.
Return values
int
Returns
int The number of bytes written. 0 indicates and error.

Definition at line 1082 of file StreamWrapper.php.

token ( )

EXPERT: Get the auth token for this wrapper.

Return values
stringA token.
See Also
object()

Definition at line 1234 of file StreamWrapper.php.

unlink (   $path)

Unlink a file.

This removes the remote copy of the file. Like a normal unlink operation, it does not destroy the (local) file handle until the file is closed. Therefore you can continue accessing the object locally.

Note that OpenStack Swift does not draw a distinction between file objects and "directory" objects (where the latter is a 0-byte object). This will delete either one. If you are using directory markers, not that deleting a marker will NOT delete the contents of the "directory".

Attention
You will need to use HPCloud::Bootstrap::setConfiguration() to set the necessary stream configuration, since unlink() does not take a context.
Parameters
string$pathThe URL.
Return values
boolean
Returns
boolean TRUE if the file was deleted, FALSE otherwise.

Definition at line 1109 of file StreamWrapper.php.

References $container, $name, ObjectStorage\$token, ObjectStorage\$url, StreamWrapper\initializeObjectStorage(), and StreamWrapper\parseUrl().

url_stat (   $path,
  $flags 
)
writeRemote ( )
protected

Write data to the remote object storage.

Internally, this is used by flush and close.

Definition at line 700 of file StreamWrapper.php.

References ObjectStorage\container(), and StreamWrapper\cxt().

Referenced by StreamWrapper\stream_close(), and StreamWrapper\stream_flush().

Member Data Documentation

$authToken
protected

Definition at line 296 of file StreamWrapper.php.

$container
protected

The Container.

Definition at line 333 of file StreamWrapper.php.

$context

The stream context.

This is set automatically when the stream wrapper is created by PHP. Note that it is not set through a constructor.

Definition at line 292 of file StreamWrapper.php.

$contextArray = array()
protected

Definition at line 293 of file StreamWrapper.php.

$createIfNotFound = TRUE
protected

Definition at line 307 of file StreamWrapper.php.

$dirIndex = 0
protected

Definition at line 351 of file StreamWrapper.php.

$dirListing = array()
protected

Directory listing.

Used for directory methods.

Definition at line 350 of file StreamWrapper.php.

Referenced by StreamWrapperFS\testDirectoryExists().

$dirPrefix = ''
protected

Definition at line 352 of file StreamWrapper.php.

$isAppending = FALSE
protected

Definition at line 305 of file StreamWrapper.php.

$isBinary = FALSE
protected

Definition at line 300 of file StreamWrapper.php.

$isDirty = FALSE
protected

Indicate whether the local differs from remote.

When the file is modified in such a way that it needs to be written remotely, the isDirty flag is set to TRUE.

Definition at line 323 of file StreamWrapper.php.

$isNeverDirty = FALSE
protected

If this is TRUE, no data is ever sent to the remote server.

Definition at line 312 of file StreamWrapper.php.

$isReading = FALSE
protected

Definition at line 303 of file StreamWrapper.php.

$isText = TRUE
protected

Definition at line 301 of file StreamWrapper.php.

$isTruncating = FALSE
protected

Definition at line 304 of file StreamWrapper.php.

$isWriting = FALSE
protected

Definition at line 302 of file StreamWrapper.php.

$noOverwrite = FALSE
protected

Definition at line 306 of file StreamWrapper.php.

$obj
protected

The Object.

Definition at line 338 of file StreamWrapper.php.

Referenced by StreamWrapper\url_stat().

$objStream
protected

The IO stream for the Object.

Definition at line 343 of file StreamWrapper.php.

$schemeName = self::DEFAULT_SCHEME
protected

Definition at line 295 of file StreamWrapper.php.

$serviceCatalogCache = array()
staticprotected

Cache of auth token -> service catalog.

This will eventually be replaced by a better system, but for a system of moderate complexity, many, many file operations may be run during the course of a request. Caching the catalog can prevent numerous calls to identity services.

Definition at line 284 of file StreamWrapper.php.

$store
protected

Object storage instance.

Definition at line 328 of file StreamWrapper.php.

$triggerErrors = FALSE
protected

Definition at line 314 of file StreamWrapper.php.

const DEFAULT_SCHEME = 'swift'

Definition at line 274 of file StreamWrapper.php.


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