ABSTRACT
CloudStorageClient is the base class for classes that are used to communicate with Google Cloud Storage via the PHP streams interface.
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.
Constants
METADATA_HEADER_PREFIX
Prefix for all metadata headers used when parsing and rendering.
DEFAULT_READ_SIZE
DEFAULT_READ_CACHE_EXPIRY_SECONDS
DEFAULT_MAXIMUM_NUMBER_OF_RETRIES
DEFAULT_CONNECTION_TIMEOUT_SECONDS
DEFAULT_WRITABLE_CACHE_EXPIRY_SECONDS
READ_SCOPE
WRITE_SCOPE
FULL_SCOPE
OAUTH_TOKEN_FORMAT
PARTIAL_CONTENT_RANGE_FORMAT
FINAL_CONTENT_RANGE_FORMAT
FINAL_CONTENT_RANGE_NO_DATA
DELIMITER
FOLDER_SUFFIX
WRITABLE_TEMP_FILENAME
S_IFREG
S_IFDIR
S_IRWXU
S_IRUSR
S_IWUSR
S_IXUSR
S_IRWXG
S_IRGRP
S_IWGRP
S_IXGRP
S_IRWXO
S_IROTH
S_IWOTH
S_IXOTH
CONTENT_RANGE_REGEX
MEMCACHE_KEY_FORMAT
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
MEMCACHE_KEY_HASH_FORMAT
Memcache key format for caching the results of reads from GCS. If the key generated using the filename and range is longer than the maximum allowed memcache key we hash down the value and use this format instead.
MEMCACHE_KEY_MAX_LENGTH
The maximum length of a memcache key.
WRITABLE_MEMCACHE_KEY_FORMAT
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.
Methods
__construct
__construct(string $bucket, string $object = null, resource $context = null)
Construct an object of CloudStorageClient.
Parameters
Name | Description |
---|---|
|
The name of the bucket. |
|
The name of the object, or null if there is no object. |
|
The stream context to use. |
__destruct
__destruct()
initialize
initialize()
dir_readdir
dir_readdir()
dir_rewinddir
dir_rewinddir()
close
close()
delete
delete()
eof
eof()
flush
flush()
read
read( $count_bytes)
Parameters
Name | Description |
---|---|
|
seek
seek( $offset, $whence)
Parameters
Name | Description |
---|---|
|
|
|
stat
stat()
tell
tell()
write
write( $data)
Parameters
Name | Description |
---|---|
|
getMetaData
getMetaData()
Subclass can override this method to return the metadata of the underlying GCS object.
getContentType
getContentType()
Subclass can override this method to return the MIME content type of the underlying GCS object.
createObjectUrl
STATIC
createObjectUrl( $bucket, $object = null)
Create a URL for a target bucket and optional object.
Parameters
Name | Description |
---|---|
|
|
|
clearStatCache
STATIC
clearStatCache(string $filename = null)
Clear the stat cache.
Parameters
Name | Description |
---|---|
|
Option filename to clear from the cache. |
getReadMemcacheKey
STATIC
getReadMemcacheKey(string $url, string $range) : string
Create a memcache key for the read data cache. If the filename is long enough that the key would exceed memcache limits, then a hash of the filename and the range is used to generate the key.
We prefer the human readable key format where possible so users can easily identify which files and segments are stored in memcache.
Parameters
Name | Description |
---|---|
|
The url of the file that contains the data being cached. |
|
The range oheader f the data being cached. |
Returns
string
The memcache key to use for storing data.