class FlysystemAssetStore implements AssetStore, AssetStoreRouter, Flushable

Asset store based on flysystem Filesystem as a backend

Traits

Provides extensions to this object to integrate it with standard config API methods.

Constants

GRANTS_SESSION

Session key to use for user grants

Config options

legacy_filenames bool Enable to use legacy filename behaviour (omits hash and uses the natural filename).
keep_empty_dirs bool Flag if empty folders are allowed.
denied_response_code int Set HTTP error code for requests to secure denied assets.
missing_response_code int Set HTTP error code to use for missing secure assets
redirect_response_code int Define the HTTP Response code for request that should be temporarily redirected to a different URL. Defaults to 302.
permanent_redirect_response_code int Define the HTTP Response code for request that should be permanently redirected to a different URL. Defaults to 301.
file_response_headers array Custom headers to add to all custom file responses

Methods

static Config_ForClass
config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .

mixed
stat(string $name) deprecated

Get inherited config value

mixed
uninherited(string $name)

Gets the uninherited value for the given config option

$this
set_stat(string $name, mixed $value) deprecated

Update the config value for a given property

$this
setPublicFilesystem(Filesystem $filesystem)

Assign new flysystem backend

Filesystem
getPublicFilesystem()

Get the currently assigned flysystem backend

$this
setProtectedFilesystem(Filesystem $filesystem)

Assign filesystem to use for non-public files

Filesystem
getProtectedFilesystem()

Get filesystem to use for non-public files

array
getCapabilities()

Return list of feature capabilities of this backend as an array.

string
getVisibility(string $filename, string $hash)

Determine visibility of the given file

resource
getAsStream(string $filename, string $hash, string|null $variant = null)

Get a stream for this file

string
getAsString(string $filename, string $hash, string|null $variant = null)

Get contents of a given file

string
getAsURL(string $filename, string $hash, string|null $variant = null, bool $grant = true)

Get the url for the file

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

Assign a local file to the backend.

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

Assign a set of data to the backend

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

Assign a stream to the backend

bool
delete(string $filename, string $hash)

Delete a file (and all variants) identified by the given filename and hash

string
rename(string $filename, string $hash, string $newName)

Rename a file (and all variants) to a new filename

string|null
copy(string $filename, string $hash, string $newName)

Copy a file (and all variants) to a new filename

publish(string $filename, string $hash)

Publicly expose the file (and all variants) identified by the given filename and hash

swapPublish($filename, $hash)

Similar to publish, only any existing files that would be overriden by publishing will be moved back to the protected store.

protect(string $filename, string $hash)

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

grant(string $filename, string $hash)

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

revoke(string $filename, string $hash)

Revoke access to the given file for the current user.

bool
canView(string $filename, string $hash)

Check if the current user can view the given file.

array|null
getMetadata(string $filename, string $hash, string|null $variant = null)

Get metadata for this file, if available

string
getMimeType(string $filename, string $hash, string|null $variant = null)

Get mime type of this file

bool
exists(string $filename, string $hash, string|null $variant = null)

Determine if a file exists with the given tuple

static 
flush()

Ensure each adapter re-generates its own server configuration files

getResponseFor(string $asset)

Generate a custom HTTP response for a request to a given asset, identified by a path.

normalisePath($fileID)

No description

normalise($filename, $hash)

No description

Details

in Configurable at line 20
static Config_ForClass config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .

....).

Return Value

Config_ForClass

in Configurable at line 32
mixed stat(string $name) deprecated

deprecated 5.0 Use ->config()->get() instead

Get inherited config value

Parameters

string $name

Return Value

mixed

in Configurable at line 44
mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

in Configurable at line 57
$this set_stat(string $name, mixed $value) deprecated

deprecated 5.0 Use ->config()->set() instead

Update the config value for a given property

Parameters

string $name
mixed $value

Return Value

$this

at line 146
$this setPublicFilesystem(Filesystem $filesystem)

Assign new flysystem backend

Parameters

Filesystem $filesystem

Return Value

$this

Exceptions

InvalidArgumentException

at line 161
Filesystem getPublicFilesystem()

Get the currently assigned flysystem backend

Return Value

Filesystem

Exceptions

LogicException

at line 176
$this setProtectedFilesystem(Filesystem $filesystem)

Assign filesystem to use for non-public files

Parameters

Filesystem $filesystem

Return Value

$this

Exceptions

InvalidArgumentException

at line 191
Filesystem getProtectedFilesystem()

Get filesystem to use for non-public files

Return Value

Filesystem

Exceptions

LogicException

at line 428
array getCapabilities()

Return list of feature capabilities of this backend as an array.

Array keys will be the options supported by $config, and the values will be the list of accepted values for each option (or true if any value is allowed).

Return Value

array

at line 444
string getVisibility(string $filename, string $hash)

Determine visibility of the given file

Parameters

string $filename
string $hash

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 454
resource getAsStream(string $filename, string $hash, string|null $variant = null)

Get a stream for this file

Parameters

string $filename Filename (not including assets)
string $hash sha1 hash of the file content. If a variant is requested, this is the hash of the file before it was modified.
string|null $variant Optional variant string for this file

Return Value

resource Data stream

at line 464
string getAsString(string $filename, string $hash, string|null $variant = null)

Get contents of a given file

Parameters

string $filename Filename (not including assets)
string $hash sha1 hash of the file content. If a variant is requested, this is the hash of the file before it was modified.
string|null $variant Optional variant string for this file

Return Value

string Data from the file.

at line 474
string getAsURL(string $filename, string $hash, string|null $variant = null, bool $grant = true)

Get the url for the file

Parameters

string $filename Filename (not including assets)
string $hash sha1 hash of the file content. If a variant is requested, this is the hash of the file before it was modified.
string|null $variant Optional variant string for this file
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 this resource

at line 503
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 529
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 543
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 593
bool delete(string $filename, string $hash)

Delete a file (and all variants) identified by the given filename and hash

Parameters

string $filename
string $hash

Return Value

bool Flag if a file was deleted

at line 608
string rename(string $filename, string $hash, string $newName)

Rename a file (and all variants) to a new filename

Parameters

string $filename
string $hash
string $newName

Return Value

string Updated Filename, or null if rename failed

at line 657
string|null copy(string $filename, string $hash, string $newName)

Copy a file (and all variants) to a new filename

Parameters

string $filename
string $hash
string $newName

Return Value

string|null Updated Filename, or null if copy failed

at line 782
publish(string $filename, string $hash)

Publicly expose the file (and all variants) identified by the given filename and hash

Parameters

string $filename Filename (not including assets)
string $hash sha1 hash of the file content.

at line 808
swapPublish($filename, $hash)

Similar to publish, only any existing files that would be overriden by publishing will be moved back to the protected store.

Parameters

$filename
$hash

at line 879
protect(string $filename, string $hash)

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

A protected file can be granted access to users on a per-session or per-user basis as response to any future invocations of {see grant()} or {see getAsURL()} with $grant = true

Parameters

string $filename Filename (not including assets)
string $hash sha1 hash of the file content.

at line 966
grant(string $filename, string $hash)

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.

Parameters

string $filename
string $hash

at line 977
revoke(string $filename, string $hash)

Revoke access to the given file for the current user.

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

Parameters

string $filename
string $hash

at line 994
bool canView(string $filename, string $hash)

Check if the current user can view the given file.

Parameters

string $filename
string $hash

Return Value

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

at line 1209
array|null getMetadata(string $filename, string $hash, string|null $variant = null)

Get metadata for this file, if available

Parameters

string $filename Filename (not including assets)
string $hash sha1 hash of the file content. If a variant is requested, this is the hash of the file before it was modified.
string|null $variant Optional variant string for this file

Return Value

array|null File information, or null if no metadata available

at line 1220
string getMimeType(string $filename, string $hash, string|null $variant = null)

Get mime type of this file

Parameters

string $filename Filename (not including assets)
string $hash sha1 hash of the file content. If a variant is requested, this is the hash of the file before it was modified.
string|null $variant Optional variant string for this file

Return Value

string Mime type for this file

at line 1231
bool exists(string $filename, string $hash, string|null $variant = null)

Determine if a file exists with the given tuple

Parameters

string $filename Filename (not including assets)
string $hash sha1 hash of the file content. If a variant is requested, this is the hash of the file before it was modified.
string|null $variant Optional variant string for this file

Return Value

bool Flag as to whether the file exists

at line 1427
static flush()

Ensure each adapter re-generates its own server configuration files

at line 1450
HTTPResponse getResponseFor(string $asset)

Generate a custom HTTP response for a request to a given asset, identified by a path.

Parameters

string $asset Asset path name, omitting any leading 'assets'

Return Value

HTTPResponse

Exceptions

HTTPResponse_Exception

at line 1577
normalisePath($fileID)

Parameters

$fileID

at line 1587
normalise($filename, $hash)

Parameters

$filename
$hash