SilverStripe\Assets\Storage\AssetStore
Represents an abstract asset persistence layer. Acts as a backend to files.
Asset storage is identified by the following values arranged into a tuple:
- "Filename" - Descriptive path for a file, although not necessarily a physical location. This could include
custom directory names as a parent, as well as an extension.
- "Hash" - The SHA1 of the file. This means that multiple files with the same Filename could be
stored independently (depending on implementation) as long as they have different hashes.
When a variant is identified, this value will refer to the hash of the file it was generated
from, not the hash of the actual generated file.
- "Variant" - An arbitrary string (which should not contain filesystem invalid characters) used
to identify an asset which is a variant of an original. The asset storage backend has no knowledge
of the mechanism used to generate this file, and is up to user code to perform the actual
generation. An empty variant identifies this file as the original file.
Write options have an additional $config parameter to provide additional options to the backend.
This is an associative array. Standard array options include 'visibility' and 'conflict'.
'conflict' config option determines the conflict resolution mechanism.
When assets are stored in the backend, user code may request one of the following conflict resolution
mechanisms:
- CONFLICT_OVERWRITE - If there is an existing file with this tuple, overwrite it.
- CONFLICT_RENAME - If there is an existing file with this tuple, pick a new Filename for it and return it.
This option is not allowed for use when storing variants, which should not modify the underlying
Filename tuple value.
- CONFLICT_USE_EXISTING - If there is an existing file with this tuple, return the tuple for the
existing file instead.
- CONFLICT_EXCEPTION - If there is an existing file with this tuple, throw an exception.
'visibility' config option determines whether the file should be marked as publicly visible.
This may be assigned to one of the below values:
- VISIBILITY_PUBLIC: This file may be accessed by any public user.
- VISIBILITY_PROTECTED: This file must be whitelisted for individual users before being made available to that user.
Synopsis
- // constants
- const CONFLICT_EXCEPTION = 'exception';
- const CONFLICT_OVERWRITE = 'overwrite';
- const CONFLICT_RENAME = 'rename';
- const CONFLICT_USE_EXISTING = 'existing';
- const VISIBILITY_PROTECTED = 'protected';
- const VISIBILITY_PUBLIC = 'public';
- // methods
- public array getCapabilities()
- public array setFromString()
- public array setFromLocalFile()
- public array setFromStream()
- public string getAsString()
- public resource getAsStream()
- public string getAsURL()
- public array|null getMetadata()
- public string getMimeType()
- public string getVisibility()
- public bool exists()
- public bool delete()
- public string rename()
- public string|null copy()
- public void publish()
- public void protect()
- public void grant()
- public void revoke()
- public bool canView()
Constants
Name | Value |
---|---|
CONFLICT_EXCEPTION | 'exception' |
CONFLICT_OVERWRITE | 'overwrite' |
CONFLICT_RENAME | 'rename' |
CONFLICT_USE_EXISTING | 'existing' |
VISIBILITY_PROTECTED | 'protected' |
VISIBILITY_PUBLIC | 'public' |
Methods
public
- canView() — Check if the current user can view the given file.
- copy() — Copy a file (and all variants) to a new filename
- delete() — Delete a file (and all variants) identified by the given filename and hash
- exists() — Determine if a file exists with the given tuple
- getAsStream() — Get a stream for this file
- getAsString() — Get contents of a given file
- getAsURL() — Get the url for the file
- getCapabilities() — Return list of feature capabilities of this backend as an array.
- getMetadata() — Get metadata for this file, if available
- getMimeType() — Get mime type of this file
- getVisibility() — Determine visibility of the given file
- grant() — Ensures that access to the specified protected file is granted for the current user.
- protect() — Protect a file (and all variants) from public access, identified by the given filename and hash.
- publish() — Publicly expose the file (and all variants) identified by the given filename and hash
- rename() — Rename a file (and all variants) to a new filename
- revoke() — Revoke access to the given file for the current user.
- setFromLocalFile() — Assign a local file to the backend.
- setFromStream() — Assign a stream to the backend
- setFromString() — Assign a set of data to the backend