class TestAssetStore extends FlysystemAssetStore implements TestOnly

Allows you to mock a backend store in a custom directory beneath assets.

Only to be used for mocking test fixtures

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

denied_response_code int Enable disclosure of secure assets

Properties

static null|bool $seekable_override Set to true|false to override all isSeekableStream calls
static string $basedir Base dir of current file

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

static 
activate(string $basedir)

Set this store as the new asset backend

static string
base_path()

Get absolute path to basedir

static 
reset()

Reset defaults for this store

static string
getLocalPath(AssetContainer $asset, boolean $forceProtected = false, boolean $relative = false)

Helper method to get local filesystem path for this file

cleanFilename($filename)

No description

getFileID($filename, $hash, $variant = null)

No description

parseFileID($fileID)

No description

getOriginalFilename($fileID)

No description

getFilesystemFor($fileID)

No description

removeVariant($fileID)

No description

getDefaultConflictResolution($variant)

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

in FlysystemAssetStore at line 147
$this setPublicFilesystem(Filesystem $filesystem)

Assign new flysystem backend

Parameters

Filesystem $filesystem

Return Value

$this

Exceptions

InvalidArgumentException

in FlysystemAssetStore at line 162
Filesystem getPublicFilesystem()

Get the currently assigned flysystem backend

Return Value

Filesystem

Exceptions

LogicException

in FlysystemAssetStore at line 177
$this setProtectedFilesystem(Filesystem $filesystem)

Assign filesystem to use for non-public files

Parameters

Filesystem $filesystem

Return Value

$this

Exceptions

InvalidArgumentException

in FlysystemAssetStore at line 192
Filesystem getProtectedFilesystem()

Get filesystem to use for non-public files

Return Value

Filesystem

Exceptions

LogicException

in FlysystemAssetStore at line 429
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

in FlysystemAssetStore at line 445
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

in FlysystemAssetStore at line 455
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

in FlysystemAssetStore at line 465
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.

in FlysystemAssetStore at line 475
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

in FlysystemAssetStore at line 504
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.

in FlysystemAssetStore at line 530
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.

in FlysystemAssetStore at line 544
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.

in FlysystemAssetStore at line 594
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

in FlysystemAssetStore at line 609
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

in FlysystemAssetStore at line 658
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

in FlysystemAssetStore at line 783
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.

in FlysystemAssetStore at line 809
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

in FlysystemAssetStore at line 880
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.

in FlysystemAssetStore at line 967
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

in FlysystemAssetStore at line 978
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

in FlysystemAssetStore at line 995
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.

in FlysystemAssetStore at line 1210
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

in FlysystemAssetStore at line 1221
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

in FlysystemAssetStore at line 1232
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

in FlysystemAssetStore at line 1428
static flush()

Ensure each adapter re-generates its own server configuration files

in FlysystemAssetStore at line 1451
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

in FlysystemAssetStore at line 1578
normalisePath($fileID)

Parameters

$fileID

in FlysystemAssetStore at line 1588
normalise($filename, $hash)

Parameters

$filename
$hash

at line 59
static activate(string $basedir)

Set this store as the new asset backend

Parameters

string $basedir Basedir to store assets, which will be placed beneath 'assets' folder

at line 108
static string base_path()

Get absolute path to basedir

Return Value

string

at line 119
static reset()

Reset defaults for this store

at line 140
static string getLocalPath(AssetContainer $asset, boolean $forceProtected = false, boolean $relative = false)

Helper method to get local filesystem path for this file

Parameters

AssetContainer $asset
boolean $forceProtected
boolean $relative Return path relative to asset store root.

Return Value

string

at line 162
cleanFilename($filename)

Parameters

$filename

at line 167
getFileID($filename, $hash, $variant = null)

Parameters

$filename
$hash
$variant

at line 172
parseFileID($fileID)

Parameters

$fileID

at line 177
getOriginalFilename($fileID)

Parameters

$fileID

at line 182
getFilesystemFor($fileID)

Parameters

$fileID

at line 187
removeVariant($fileID)

Parameters

$fileID

at line 192
getDefaultConflictResolution($variant)

Parameters

$variant