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

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

Assign a set of data to the backend

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

Assign a local file to the backend.

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

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

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. {see \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. {see \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. {see \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()

Return Value

string

Data from the file in this container

resource getStream()

Return Value

resource

Data stream to the asset in this container

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

string getAbsoluteURL()

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).

{see \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 {see AssetStore::publish}

protectFile()

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

{see \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.