interface AssetContainer (View source)

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

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

Assign a set of data to the backend

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

Assign a local file to the backend.

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

Assign a stream to the backend

public
string
getString()

No description

public
resource
getStream()

No description

public
string
getURL(bool $grant = true)

No description

public
string
getAbsoluteURL()

No description

public
array|null
getMetaData()

Get metadata for this file

public
string
getMimeType()

Get mime type

public
int
getAbsoluteSize()

Return file size in bytes.

public
bool
getIsImage()

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

public
string
getVisibility()

Determine visibility of the given file

public
bool
exists()

Determine if this container has a valid value

public
string
getFilename()

Get value of filename

public
string
getHash()

Get value of hash

public
string
getVariant()

Get value of variant

public
bool
deleteFile()

Delete a file (and all variants).

public
string
renameFile(string $newName)

Rename to new filename, and point to new file

public
string
copyFile(string $newName)

Copy to new filename.

public
publishFile()

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

public
protectFile()

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

public
grantFile()

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

public
revokeFile()

Revoke access to the given file for the current user.

public
bool
canViewFile()

Check if the current user can view the given file.

Details

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

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. {\SilverStripe\Assets\Storage\AssetStore}

Return Value

array

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

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

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. {\SilverStripe\Assets\Storage\AssetStore}

Return Value

array

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

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

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. {\SilverStripe\Assets\Storage\AssetStore}

Return Value

array

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

string getString()

No description

Return Value

string

Data from the file in this container

resource getStream()

No description

Return Value

resource

Data stream to the asset in this container

string getURL(bool $grant = true)

No description

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

string getAbsoluteURL()

No description

Return Value

string

The absolute URL to the asset in this container

array|null getMetaData()

Get metadata for this file

Return Value

array|null

File information

string getMimeType()

Get mime type

Return Value

string

Mime type for this file

int getAbsoluteSize()

Return file size in bytes.

Return Value

int

bool getIsImage()

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

Return Value

bool

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

bool exists()

Determine if this container has a valid value

Return Value

bool

Flag as to whether the file exists

string getFilename()

Get value of filename

Return Value

string

string getHash()

Get value of hash

Return Value

string

string getVariant()

Get value of variant

Return Value

string

bool deleteFile()

Delete a file (and all variants).

{\SilverStripe\Assets\Storage\AssetStore::delete()}

Return Value

bool

Flag if a file was deleted

string renameFile(string $newName)

Rename to new filename, and point to new file

Parameters

string $newName

Return Value

string

Updated Filename

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

publishFile()

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

protectFile()

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

{\SilverStripe\Assets\Storage\AssetStore::protect()}

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.

revokeFile()

Revoke access to the given file for the current user.

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

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.