App Engine PHP SDK  v1 rev.445
The PHP runtime is available as an experimental Preview feature.
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
google\appengine\ext\cloud_storage_streams\CloudStorageClient Class Reference
Inheritance diagram for google\appengine\ext\cloud_storage_streams\CloudStorageClient:
google\appengine\ext\cloud_storage_streams\CloudStorageDeleteClient google\appengine\ext\cloud_storage_streams\CloudStorageDirectoryClient google\appengine\ext\cloud_storage_streams\CloudStorageReadClient google\appengine\ext\cloud_storage_streams\CloudStorageRenameClient google\appengine\ext\cloud_storage_streams\CloudStorageUrlStatClient google\appengine\ext\cloud_storage_streams\CloudStorageWriteClient

Public Member Functions

 __construct ($bucket, $object=null, $context=null)
 
 initialize ()
 
 dir_readdir ()
 
 dir_rewinddir ()
 
 close ()
 
 delete ()
 
 eof ()
 
 flush ()
 
 read ($count_bytes)
 
 seek ($offset, $whence)
 
 stat ()
 
 tell ()
 
 write ($data)
 
 getMetaData ()
 
 getContentType ()
 

Static Public Member Functions

static createObjectUrl ($bucket, $object=null)
 

Public Attributes

const METADATA_HEADER_PREFIX = 'x-goog-meta-'
 
const DEFAULT_READ_SIZE = 524288
 
const DEFAULT_READ_CACHE_EXPIRY_SECONDS = 3600
 
const DEFAULT_MAXIMUM_NUMBER_OF_RETRIES = 2
 
const DEFAULT_WRITABLE_CACHE_EXPIRY_SECONDS = 600
 
const READ_SCOPE = "https://www.googleapis.com/auth/devstorage.read_only"
 
const WRITE_SCOPE = "https://www.googleapis.com/auth/devstorage.read_write"
 
const FULL_SCOPE = "https://www.googleapis.com/auth/devstorage.full_control"
 
const OAUTH_TOKEN_FORMAT = "OAuth %s"
 
const PARTIAL_CONTENT_RANGE_FORMAT = "bytes %d-%d/*"
 
const FINAL_CONTENT_RANGE_FORMAT = "bytes %d-%d/%d"
 
const FINAL_CONTENT_RANGE_NO_DATA = "bytes */%d"
 
const DELIMITER = '/'
 
const FOLDER_SUFFIX = '_$folder$'
 
const WRITABLE_TEMP_FILENAME = "/_ah_is_writable_temp_file"
 
const S_IFREG = 0100000
 
const S_IFDIR = 0040000
 
const S_IRWXU = 00700
 
const S_IRUSR = 00400
 
const S_IWUSR = 00200
 
const S_IXUSR = 00100
 
const S_IRWXG = 00070
 
const S_IRGRP = 00040
 
const S_IWGRP = 00020
 
const S_IXGRP = 00010
 
const S_IRWXO = 00007
 
const S_IROTH = 00004
 
const S_IWOTH = 00002
 
const S_IXOTH = 00001
 
const CONTENT_RANGE_REGEX = "/bytes\s+(\d+)-(\d+)\/(\d+)/i"
 
const MEMCACHE_KEY_FORMAT = "_ah_gs_read_cache_%s_%s"
 
const WRITABLE_MEMCACHE_KEY_FORMAT = "_ah_gs_write_bucket_cache_%s"
 

Static Public Attributes

static POST
 
static enable_optimistic_cache
 

Protected Member Functions

 getOAuthTokenHeader ($scopes)
 
 getRangeHeader ($start_byte, $end_byte)
 
 makeHttpRequest ($url, $method, $headers, $body=null)
 
 getHeaderValue ($header_name, $headers)
 
 createStatArray ($stat_args)
 
 tryParseCloudStorageErrorMessage ($gcs_result, &$code, &$message)
 
 getErrorMessage ($http_status_code, $http_result, $msg_prefix="Cloud Storage Error:")
 

Static Protected Member Functions

static extractMetaData (array $headers)
 

Protected Attributes

 $bucket_name
 
 $object_name
 
 $context_options = []
 
 $url
 
 $anonymous
 

Static Protected Attributes

static $METADATA_HEADERS
 
static $retry_error_codes
 
static $retry_exception_codes
 
static $valid_acl_values
 
static $upload_start_header = ["x-goog-resumable" => "start"]
 

Detailed Description

CloudStorageClient provides default fail implementations for all of the methods that the stream wrapper might potentially call. Derived classes then only implement the methods that are relevant to the operations that they perform.

Constructor & Destructor Documentation

google\appengine\ext\cloud_storage_streams\CloudStorageClient::__construct (   $bucket,
  $object = null,
  $context = null 
)

Construct an object of CloudStorageClient.

Parameters
string$bucketThe name of the bucket.
string$objectThe name of the object, or null if there is no object.
resource$contextThe stream context to use.

Member Function Documentation

static google\appengine\ext\cloud_storage_streams\CloudStorageClient::createObjectUrl (   $bucket,
  $object = null 
)
static

Create a URL for a target bucket and optional object.

google\appengine\ext\cloud_storage_streams\CloudStorageClient::createStatArray (   $stat_args)
protected

Generate the default stat() array, which is both associative and index based.

private

static google\appengine\ext\cloud_storage_streams\CloudStorageClient::extractMetaData ( array  $headers)
staticprotected

Extract metadata from HTTP response headers.

Finds all headers that begin with METADATA_HEADER_PREFIX (x-goog-meta-), strips off the prefix, and creates an associative array.

Parameters
array$headersAssociative array of HTTP headers.
Returns
array Array of parsed metadata headers.
google\appengine\ext\cloud_storage_streams\CloudStorageClient::getContentType ( )

Subclass can override this method to return the MIME content type of the underlying GCS object.

google\appengine\ext\cloud_storage_streams\CloudStorageClient::getErrorMessage (   $http_status_code,
  $http_result,
  $msg_prefix = "Cloud Storage Error:" 
)
protected

Return a formatted error message for the http response.

Parameters
int$http_status_codeThe HTTP status code returned from the last http request.
string$http_resultThe response body from the last http request.
string$msg_prefixThe prefix to add to the error message that will be generated.
Returns
string The error message for the last HTTP response.
google\appengine\ext\cloud_storage_streams\CloudStorageClient::getHeaderValue (   $header_name,
  $headers 
)
protected

Return the value of a header stored in an associative array, using a case insensitive comparison on the header name.

Parameters
$header_namestring The name of the header to lookup.
$headersarray Associative array of headers.
Returns
The value of the header if found, false otherwise.
google\appengine\ext\cloud_storage_streams\CloudStorageClient::getMetaData ( )

Subclass can override this method to return the metadata of the underlying GCS object.

google\appengine\ext\cloud_storage_streams\CloudStorageClient::getOAuthTokenHeader (   $scopes)
protected

Get the OAuth Token HTTP header for the supplied scope.

Parameters
$scopesmixed The scopes to acquire the token for.
Returns
array The HTTP authorization header for the scopes, using the applications service account. False if the call failed.
google\appengine\ext\cloud_storage_streams\CloudStorageClient::getRangeHeader (   $start_byte,
  $end_byte 
)
protected

Return a Range HTTP header.

Parameters
$start_byteint The offset of the first byte in the range.
$end_byteint The offset of the last byte in the range.
Returns
array The HTTP Range header for the supplied offsets.
google\appengine\ext\cloud_storage_streams\CloudStorageClient::makeHttpRequest (   $url,
  $method,
  $headers,
  $body = null 
)
protected

Make a request to GCS using HttpStreams.

Returns: headers array response body

google\appengine\ext\cloud_storage_streams\CloudStorageClient::tryParseCloudStorageErrorMessage (   $gcs_result,
$code,
$message 
)
protected

Given an xml based error response from Cloud Storage, try and extract the error code and error message according to the schema described at https://developers.google.com/storage/docs/reference-status

Parameters
string$gcs_resultThe response body of the last call to Google Cloud Storage.
string$codeReference variable where the error code for the last message will be returned.
string$messageReference variable where the error detail for the last message will be returned.
Returns
bool True if the error code and message could be extracted, false otherwise.

Member Data Documentation

google\appengine\ext\cloud_storage_streams\CloudStorageClient::$METADATA_HEADERS
staticprotected
Initial value:
= [
'Cache-Control',
'Content-Disposition',
'Content-Encoding',
'Content-Language',
'Content-Type',
]

Headers that may be controlled by the user through the stream context.

google\appengine\ext\cloud_storage_streams\CloudStorageClient::$retry_error_codes
staticprotected
Initial value:
= [HttpResponse::REQUEST_TIMEOUT,
HttpResponse::INTERNAL_SERVER_ERROR,
HttpResponse::BAD_GATEWAY,
HttpResponse::SERVICE_UNAVAILABLE,
HttpResponse::GATEWAY_TIMEOUT]
google\appengine\ext\cloud_storage_streams\CloudStorageClient::$retry_exception_codes
staticprotected
Initial value:
= [
ErrorCode::DEADLINE_EXCEEDED,
ErrorCode::FETCH_ERROR,
ErrorCode::INTERNAL_TRANSIENT_ERROR]
google\appengine\ext\cloud_storage_streams\CloudStorageClient::$valid_acl_values
staticprotected
Initial value:
= ["private",
"public-read",
"public-read-write",
"authenticated-read",
"bucket-owner-read",
"bucket-owner-full-control"]
google\appengine\ext\cloud_storage_streams\CloudStorageClient::enable_optimistic_cache
static
Initial value:
=> false,
"max_retries" => self::DEFAULT_MAXIMUM_NUMBER_OF_RETRIES,
"read_cache_expiry_seconds" => self::DEFAULT_READ_CACHE_EXPIRY_SECONDS,
"writable_cache_expiry_seconds" =>
self::DEFAULT_WRITABLE_CACHE_EXPIRY_SECONDS,
]
const google\appengine\ext\cloud_storage_streams\CloudStorageClient::MEMCACHE_KEY_FORMAT = "_ah_gs_read_cache_%s_%s"

Memcache key format for caching the results of reads from GCS. The parameters are the object url (as a string) and the read range, as a string (e.g. bytes=0-512000). Example key for a cloud storage file gs://bucket/object.png _ah_gs_read_cache_https://storage.googleapis.com/bucket/object.png_bytes=0-524287

const google\appengine\ext\cloud_storage_streams\CloudStorageClient::METADATA_HEADER_PREFIX = 'x-goog-meta-'

Prefix for all metadata headers used when parsing and rendering.

google\appengine\ext\cloud_storage_streams\CloudStorageClient::POST
static
Initial value:
=> RequestMethod::POST,
"HEAD" => RequestMethod::HEAD,
"PUT" => RequestMethod::PUT,
"DELETE" => RequestMethod::DELETE,
"PATCH" => RequestMethod::PATCH
]
const google\appengine\ext\cloud_storage_streams\CloudStorageClient::WRITABLE_MEMCACHE_KEY_FORMAT = "_ah_gs_write_bucket_cache_%s"

Memcache key format for caching the results of checking if a bucket is writable. The only way to check if an app can write to a bucket is by actually writing a file. As the ACL on a bucket is unlikely to change then we can cache the result.


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