interface AssetContainer

Represents a container for a specific asset.

This is used as a use-agnostic interface to a single asset backed by an AssetStore

Note that there are no setter equivalents for each of getHash, getVariant and getFilename. User code should utilise the setFrom* methods instead.

Methods

array
setFromString(string $data, string $filename, string $hash = null, string $variant = null, array $config = array())

Assign a set of data to the backend

array
setFromLocalFile(string $path, string $filename = null, string $hash = null, string $variant = null, array $config = array())

Assign a local file to the backend.

array
setFromStream(resource $stream, string $filename, string $hash = null, string $variant = null, array $config = array())

Assign a stream to the backend

string
getString()

No description

resource
getStream()

No description

string
getURL(bool $grant = true)

No description

string
getAbsoluteURL()

No description

array|null
getMetaData()

Get metadata for this file

string
getMimeType()

Get mime type

int
getAbsoluteSize()

Return file size in bytes.

bool
getIsImage()

Determine if a valid non-empty image exists behind this asset

string
getVisibility()

Determine visibility of the given file

bool
exists()

Determine if this container has a valid value

string
getFilename()

Get value of filename

string
getHash()

Get value of hash

string
getVariant()

Get value of variant

bool
deleteFile()

Delete a file (and all variants).

string
renameFile(string $newName)

Rename to new filename, and point to new file

string
copyFile(string $newName)

Copy to new filename.

publishFile()

Publicly expose the file (and all variants) identified by the given filename and hash {see AssetStore::publish}

protectFile()

Protect a file (and all variants) from public access, identified by the given filename and hash.

grantFile()

Ensures that access to the specified protected file is granted for the current user.

revokeFile()

Revoke access to the given file for the current user.

bool
canViewFile()

Check if the current user can view the given file.

Details

at line 27
array setFromString(string $data, string $filename, string $hash = null, string $variant = null, array $config = array())

Assign a set of data to the backend

Parameters

string $data Raw binary/text content
string $filename Name for the resulting file
string $hash Hash of original file, if storing a variant.
string $variant Name of variant, if storing a variant.
array $config Write options. {see AssetStore}

Return Value

array Tuple associative array (Filename, Hash, Variant) Unless storing a variant, the hash will be calculated from the given data.

at line 41
array setFromLocalFile(string $path, string $filename = null, string $hash = null, string $variant = null, array $config = array())

Assign a local file to the backend.

Parameters

string $path Absolute filesystem path to file
string $filename Optional path to ask the backend to name as. Will default to the filename of the $path, excluding directories.
string $hash Hash of original file, if storing a variant.
string $variant Name of variant, if storing a variant.
array $config Write options. {see AssetStore}

Return Value

array Tuple associative array (Filename, Hash, Variant) Unless storing a variant, the hash will be calculated from the local file content.

at line 54
array setFromStream(resource $stream, string $filename, string $hash = null, string $variant = null, array $config = array())

Assign a stream to the backend

Parameters

resource $stream Streamable resource
string $filename Name for the resulting file
string $hash Hash of original file, if storing a variant.
string $variant Name of variant, if storing a variant.
array $config Write options. {see AssetStore}

Return Value

array Tuple associative array (Filename, Hash, Variant) Unless storing a variant, the hash will be calculated from the raw stream.

at line 59
string getString()

Return Value

string Data from the file in this container

at line 64
resource getStream()

Return Value

resource Data stream to the asset in this container

at line 74
string getURL(bool $grant = true)

Parameters

bool $grant Ensures that the url for any protected assets is granted for the current user. If set to true, and the file is currently in protected mode, the asset store will ensure the returned URL is accessible for the duration of the current session / user. This will have no effect if the file is in published mode. This will not grant access to users other than the owner of the current session.

Return Value

string public url to the asset in this container

at line 79
string getAbsoluteURL()

Return Value

string The absolute URL to the asset in this container

at line 86
array|null getMetaData()

Get metadata for this file

Return Value

array|null File information

at line 93
string getMimeType()

Get mime type

Return Value

string Mime type for this file

at line 100
int getAbsoluteSize()

Return file size in bytes.

Return Value

int

at line 107
bool getIsImage()

Determine if a valid non-empty image exists behind this asset

Return Value

bool

at line 115
string getVisibility()

Determine visibility of the given file

Return Value

string one of values defined by the constants VISIBILITY_PROTECTED or VISIBILITY_PUBLIC, or null if the file does not exist

at line 122
bool exists()

Determine if this container has a valid value

Return Value

bool Flag as to whether the file exists

at line 129
string getFilename()

Get value of filename

Return Value

string

at line 136
string getHash()

Get value of hash

Return Value

string

at line 143
string getVariant()

Get value of variant

Return Value

string

at line 151
bool deleteFile()

Delete a file (and all variants).

{see AssetStore::delete()}

Return Value

bool Flag if a file was deleted

at line 159
string renameFile(string $newName)

Rename to new filename, and point to new file

Parameters

string $newName

Return Value

string Updated Filename

at line 168
string copyFile(string $newName)

Copy to new filename.

This will not automatically point to the new file (as renameFile() does)

Parameters

string $newName

Return Value

string Updated filename

at line 174
publishFile()

Publicly expose the file (and all variants) identified by the given filename and hash {see AssetStore::publish}

at line 180
protectFile()

Protect a file (and all variants) from public access, identified by the given filename and hash.

{see AssetStore::protect()}

at line 190
grantFile()

Ensures that access to the specified protected file is granted for the current user.

If this file is currently in protected mode, the asset store will ensure the returned asset for the duration of the current session / user. This will have no effect if the file is in published mode. This will not grant access to users other than the owner of the current session. Does not require a member to be logged in.

at line 196
revokeFile()

Revoke access to the given file for the current user.

Note: This will have no effect if the given file is public

at line 203
bool canViewFile()

Check if the current user can view the given file.

Return Value

bool True if the file is verified and grants access to the current session / user.