class FlysystemAssetStore implements AssetStore, AssetStoreRouter, Flushable (View source)

Asset store based on flysystem Filesystem as a backend

Traits

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

Allows an object to have extensions applied to it.

Allows an object to declare a set of custom methods

Constants

GRANTS_SESSION

Session key to use for user grants

Config options

extensions array

An array of extension names and parameters to be applied to this object upon construction.

from  Extensible
unextendable_classes array

Classes that cannot be extended

from  Extensible
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

Properties

protected static array $extra_methods

Custom method sources

from  CustomMethods
protected array $extra_method_registers

Name of methods to invoke by defineMethods for this instance

from  CustomMethods
protected static array $built_in_methods

Non-custom methods

from  CustomMethods
protected Extension[] $extension_instances from  Extensible
protected callable[][] $beforeExtendCallbacks

List of callbacks to call prior to extensions having extend called on them, each grouped by methodName.

from  Extensible
protected callable[][] $afterExtendCallbacks

List of callbacks to call after extensions having extend called on them, each grouped by methodName.

from  Extensible

Methods

public static 
config()

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

public
mixed
stat(string $name) deprecated

Get inherited config value

public
mixed
uninherited(string $name)

Gets the uninherited value for the given config option

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

Update the config value for a given property

public
mixed
__call(string $method, array $arguments)

Attempts to locate and call a method dynamically added to a class at runtime if a default cannot be located

protected
defineMethods()

Adds any methods from Extension instances attached to this object.

protected
registerExtraMethodCallback(string $name, callable $callback)

Register an callback to invoke that defines extra methods

public
bool
hasMethod(string $method)

Return TRUE if a method exists on this object

protected
array
getExtraMethodConfig(string $method)

Get meta-data details on a named method

public
array
allMethodNames(bool $custom = false)

Return the names of all the methods available on this object

protected
array
findMethodsFromExtension(object $extension) deprecated

No description

protected
addMethodsFrom(string $property, string|int $index = null)

Add all the methods from an object property (which is an Extension) to this object.

protected
removeMethodsFrom(string $property, string|int $index = null)

Add all the methods from an object property (which is an Extension) to this object.

protected
addWrapperMethod(string $method, string $wrap)

Add a wrapper method - a method which points to another method with a different name. For example, Thumbnail(x) can be wrapped to generateThumbnail(x)

protected
addCallbackMethod(string $method, callable $callback)

Add callback as a method.

protected
beforeExtending(string $method, callable $callback)

Allows user code to hook into Object::extend prior to control being delegated to extensions. Each callback will be reset once called.

protected
afterExtending(string $method, callable $callback)

Allows user code to hook into Object::extend after control being delegated to extensions. Each callback will be reset once called.

protected
constructExtensions() deprecated

No description

protected
defineExtensionMethods()

Adds any methods from Extension instances attached to this object.

public static 
bool
add_extension(string $classOrExtension, string $extension = null)

Add an extension to a specific class.

public static 
remove_extension(string $extension)

Remove an extension from a class.

public static 
array
get_extensions(string $class = null, bool $includeArgumentString = false)

No description

public static 
array|null
get_extra_config_sources(string $class = null)

Get extra config sources for this class

public static 
bool
has_extension(string $classOrExtension, string $requiredExtension = null, bool $strict = false)

Return TRUE if a class has a specified extension.

public
array
invokeWithExtensions(string $method, mixed $a1 = null, mixed $a2 = null, mixed $a3 = null, mixed $a4 = null, mixed $a5 = null, mixed $a6 = null, mixed $a7 = null)

Calls a method if available on both this object and all applied Extensions, and then attempts to merge all results into an array

public
array
extend(string $method, mixed $a1 = null, mixed $a2 = null, mixed $a3 = null, mixed $a4 = null, mixed $a5 = null, mixed $a6 = null, mixed $a7 = null)

Run the given function on all of this object's extensions. Note that this method originally returned void, so if you wanted to return results, you're hosed

public
Extension|null
getExtensionInstance(string $extension)

Get an extension instance attached to this object by name.

public
bool
hasExtension(string $extension)

Returns TRUE if this object instance has a specific extension applied in $extension_instances. Extension instances are initialized at constructor time, meaning if you use add_extension() afterwards, the added extension will just be added to new instances of the extended class. Use the static method has_extension() to check if a class (not an instance) has a specific extension.

public
getExtensionInstances()

Get all extension instances for this specific object instance.

public
$this
setPublicFilesystem(Filesystem $filesystem)

Assign new flysystem backend

public
Filesystem
getPublicFilesystem()

Get the currently assigned flysystem backend

public
$this
setProtectedFilesystem(Filesystem $filesystem)

Assign filesystem to use for non-public files

public
Filesystem
getProtectedFilesystem()

Get filesystem to use for non-public files

public
setPublicResolutionStrategy(FileResolutionStrategy $publicResolutionStrategy)

No description

public
setProtectedResolutionStrategy(FileResolutionStrategy $protectedResolutionStrategy)

No description

protected
Filesystem
getFilesystemFor(string $fileID) deprecated

Return the store that contains the given fileID

protected
mixed
applyToFileOnFilesystem(callable $callable, ParsedFileID $parsedFileID, bool $strictHashCheck = true)

Generic method to apply an action to a file regardless of what FileSystem it's on. The action to perform should be provided as a closure expecting the following signature:

function(ParsedFileID $parsedFileID, FileSystem $fs, FileResolutionStrategy $strategy, $visibility)

protected
mixed
applyToFileIDOnFilesystem(callable $callable, string $fileID, bool $strictHashCheck = true)

Equivalent to applyToFileOnFilesystem, only it expects a `fileID1 string instead of a ParsedFileID.

public
array
getCapabilities()

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

public
string
getVisibility(string $filename, string $hash)

Determine visibility of the given file

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

Get a stream for this file

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

Get contents of a given file

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

Get the url for the file

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
setFromString(string $data, string $filename, string $hash = null, string $variant = null, array $config = [])

Assign a set of data 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
bool
delete(string $filename, string $hash)

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

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

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

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

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

protected
bool
deleteFromFilesystem(string $fileID, Filesystem $filesystem) deprecated

Delete the given file (and any variants) in the given {Filesystem}

protected
bool
deleteFromFileStore(ParsedFileID $parsedFileID, Filesystem $fs, FileResolutionStrategy $strategy)

Delete the given file (and any variants) in the given {Filesystem}

protected
truncateDirectory(string $dirname, Filesystem $filesystem)

Clear directory if it's empty

protected
findVariants(string $fileID, Filesystem $filesystem) deprecated

Returns an iterable {Generator} of all files / variants for the given $fileID in the given $filesystem This includes the empty (no) variant.

public
publish(string $filename, string $hash)

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

public
swapPublish($filename, $hash)

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

public
protect(string $filename, string $hash)

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

protected
moveBetweenFilesystems(string $fileID, Filesystem $from, Filesystem $to) deprecated

Move a file (and its associative variants) between filesystems

protected
moveBetweenFileStore(ParsedFileID $parsedFileID, Filesystem $from, FileResolutionStrategy $fromStrategy, Filesystem $to, FileResolutionStrategy $toStrategy, $swap = false)

Move a file and its associated variant from one file store to another adjusting the file name format.

public
grant(string $filename, string $hash)

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

public
revoke(string $filename, string $hash)

Revoke access to the given file for the current user.

public
bool
canView(string $filename, string $hash)

Check if the current user can view the given file.

protected
bool
isGranted(string|ParsedFileID $fileID)

Determine if a grant exists for the given FileID

protected
string
getStreamSHA1(resource $stream) deprecated

get sha1 hash from stream

protected
string
getStreamAsFile(resource $stream)

Get stream as a file

protected
bool
isSeekableStream(resource $stream)

Determine if this stream is seekable

protected
array
writeWithCallback(callable $callback, string $filename, string $hash, string $variant = null, array $config = [])

Invokes the conflict resolution scheme on the given content, and invokes a callback if the storage request is approved.

protected
string
getDefaultConflictResolution(string $variant)

Choose a default conflict resolution

protected
bool
useLegacyFilenames() deprecated

Determine if legacy filenames should be used. This no longuer makes any difference with the introduction of FileResolutionStrategies.

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

Get metadata for this file, if available

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

Get mime type of this file

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

Determine if a file exists with the given tuple

protected
string|false
resolveConflicts(string $conflictResolution, string $fileID)

Determine the path that should be written to, given the conflict resolution scheme

protected
fileGeneratorFor(string $fileID)

Get an asset renamer for the given filename.

protected
string
cleanFilename(string $filename) deprecated

Performs filename cleanup before sending it back.

protected
array
parseFileID(string $fileID) deprecated

Get Filename and Variant from FileID

protected
string
getOriginalFilename(string $fileID) deprecated

Given a FileID, map this back to the original filename, trimming variant and hash

protected
string
getVariant(string $fileID) deprecated

Get variant from this file

protected
string
removeVariant(string $fileID) deprecated

Remove variant from a fileID

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

Map file tuple (hash, name, variant) to a filename to be used by flysystem

public static 
flush()

Ensure each adapter re-generates its own server configuration files

public
getResponseFor(string $asset)

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

protected
createResponseFor(Filesystem $flysystem, string $fileID)

Generate an {HTTPResponse} for the given file from the source filesystem

protected
createDeniedResponse()

Generate a response for requests to a denied protected file

protected
createMissingResponse()

Generate a response for missing file requests

protected
createErrorResponse(int $code)

Create a response with the given error code

public
normalisePath($fileID)

No description

public
normalise($filename, $hash)

No description

Details

static Config_ForClass config()

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

Return Value

Config_ForClass

mixed stat(string $name) deprecated

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

Get inherited config value

Parameters

string $name

Return Value

mixed

mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

$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

mixed __call(string $method, array $arguments)

Attempts to locate and call a method dynamically added to a class at runtime if a default cannot be located

You can add extra methods to a class using Extensions}, {@link Object::createMethod() or Object::addWrapperMethod()

Parameters

string $method
array $arguments

Return Value

mixed

Exceptions

BadMethodCallException

protected defineMethods()

Adds any methods from Extension instances attached to this object.

All these methods can then be called directly on the instance (transparently mapped through __call()}), or called explicitly through {@link extend().

protected registerExtraMethodCallback(string $name, callable $callback)

Register an callback to invoke that defines extra methods

Parameters

string $name
callable $callback

bool hasMethod(string $method)

Return TRUE if a method exists on this object

This should be used rather than PHP's inbuild method_exists() as it takes into account methods added via extensions

Parameters

string $method

Return Value

bool

protected array getExtraMethodConfig(string $method)

Get meta-data details on a named method

Parameters

string $method

Return Value

array

List of custom method details, if defined for this method

array allMethodNames(bool $custom = false)

Return the names of all the methods available on this object

Parameters

bool $custom

include methods added dynamically at runtime

Return Value

array

protected array findMethodsFromExtension(object $extension) deprecated

deprecated 4.13.0 Will be replaced by findMethodsFrom() in CMS 5

No description

Parameters

object $extension

Return Value

array

protected addMethodsFrom(string $property, string|int $index = null)

Add all the methods from an object property (which is an Extension) to this object.

Parameters

string $property

the property name

string|int $index

an index to use if the property is an array

Exceptions

InvalidArgumentException

protected removeMethodsFrom(string $property, string|int $index = null)

Add all the methods from an object property (which is an Extension) to this object.

Parameters

string $property

the property name

string|int $index

an index to use if the property is an array

protected addWrapperMethod(string $method, string $wrap)

Add a wrapper method - a method which points to another method with a different name. For example, Thumbnail(x) can be wrapped to generateThumbnail(x)

Parameters

string $method

the method name to wrap

string $wrap

the method name to wrap to

protected addCallbackMethod(string $method, callable $callback)

Add callback as a method.

Parameters

string $method

Name of method

callable $callback

Callback to invoke. Note: $this is passed as first parameter to this callback and then $args as array

protected beforeExtending(string $method, callable $callback)

Allows user code to hook into Object::extend prior to control being delegated to extensions. Each callback will be reset once called.

Parameters

string $method

The name of the method to hook into

callable $callback

The callback to execute

protected afterExtending(string $method, callable $callback)

Allows user code to hook into Object::extend after control being delegated to extensions. Each callback will be reset once called.

Parameters

string $method

The name of the method to hook into

callable $callback

The callback to execute

protected constructExtensions() deprecated

deprecated 4.0.0:5.0.0 Extensions and methods are now lazy-loaded

No description

protected defineExtensionMethods()

Adds any methods from Extension instances attached to this object.

All these methods can then be called directly on the instance (transparently mapped through __call()}), or called explicitly through {@link extend().

static bool add_extension(string $classOrExtension, string $extension = null)

Add an extension to a specific class.

The preferred method for adding extensions is through YAML config, since it avoids autoloading the class, and is easier to override in more specific configurations.

As an alternative, extensions can be added to a specific class directly in the Object::$extensions array. See SiteTree::$extensions for examples. Keep in mind that the extension will only be applied to new instances, not existing ones (including all instances created through singleton()).

Parameters

string $classOrExtension

Class that should be extended - has to be a subclass of Object

string $extension

Subclass of Extension with optional parameters as a string, e.g. "Versioned" or "Translatable('Param')"

Return Value

bool

Flag if the extension was added

See also

http://doc.silverstripe.org/framework/en/trunk/reference/dataextension

static remove_extension(string $extension)

Remove an extension from a class.

Note: This will not remove extensions from parent classes, and must be called directly on the class assigned the extension.

Keep in mind that this won't revert any datamodel additions of the extension at runtime, unless its used before the schema building kicks in (in your _config.php). Doesn't remove the extension from any Object instances which are already created, but will have an effect on new extensions. Clears any previously created singletons through singleton() to avoid side-effects from stale extension information.

Add support for removing extensions with parameters

Parameters

string $extension

class name of an Extension subclass, without parameters

static array get_extensions(string $class = null, bool $includeArgumentString = false)

No description

Parameters

string $class

If omitted, will get extensions for the current class

bool $includeArgumentString

Include the argument string in the return array, FALSE would return array("Versioned"), TRUE returns array("Versioned('Stage','Live')").

Return Value

array

Numeric array of either DataExtension class names, or eval'ed class name strings with constructor arguments.

static array|null get_extra_config_sources(string $class = null)

Get extra config sources for this class

Parameters

string $class

Name of class. If left null will return for the current class

Return Value

array|null

static bool has_extension(string $classOrExtension, string $requiredExtension = null, bool $strict = false)

Return TRUE if a class has a specified extension.

This supports backwards-compatible format (static Object::has_extension($requiredExtension)) and new format ($object->has_extension($class, $requiredExtension))

Parameters

string $classOrExtension

Class to check extension for, or the extension name to check if the second argument is null.

string $requiredExtension

If the first argument is the parent class, this is the extension to check. If left null, the first parameter will be treated as the extension.

bool $strict

if the extension has to match the required extension and not be a subclass

Return Value

bool

Flag if the extension exists

array invokeWithExtensions(string $method, mixed $a1 = null, mixed $a2 = null, mixed $a3 = null, mixed $a4 = null, mixed $a5 = null, mixed $a6 = null, mixed $a7 = null)

Calls a method if available on both this object and all applied Extensions, and then attempts to merge all results into an array

Parameters

string $method

the method name to call

mixed $a1
mixed $a2
mixed $a3
mixed $a4
mixed $a5
mixed $a6
mixed $a7

Return Value

array

List of results with nulls filtered out

array extend(string $method, mixed $a1 = null, mixed $a2 = null, mixed $a3 = null, mixed $a4 = null, mixed $a5 = null, mixed $a6 = null, mixed $a7 = null)

Run the given function on all of this object's extensions. Note that this method originally returned void, so if you wanted to return results, you're hosed

Currently returns an array, with an index resulting every time the function is called. Only adds returns if they're not NULL, to avoid bogus results from methods just defined on the parent extension. This is important for permission-checks through extend, as they use min() to determine if any of the returns is FALSE. As min() doesn't do type checking, an included NULL return would fail the permission checks.

The extension methods are defined during __construct()} in {@link defineMethods().

Parameters

string $method

the name of the method to call on each extension

mixed $a1
mixed $a2
mixed $a3
mixed $a4
mixed $a5
mixed $a6
mixed $a7

Return Value

array

Extension|null getExtensionInstance(string $extension)

Get an extension instance attached to this object by name.

Parameters

string $extension

Return Value

Extension|null

bool hasExtension(string $extension)

Returns TRUE if this object instance has a specific extension applied in $extension_instances. Extension instances are initialized at constructor time, meaning if you use add_extension() afterwards, the added extension will just be added to new instances of the extended class. Use the static method has_extension() to check if a class (not an instance) has a specific extension.

Caution: Don't use singleton()->hasExtension() as it will give you inconsistent results based on when the singleton was first accessed.

Parameters

string $extension

Classname of an Extension subclass without parameters

Return Value

bool

Extension[] getExtensionInstances()

Get all extension instances for this specific object instance.

See get_extensions() to get all applied extension classes for this class (not the instance).

This method also provides lazy-population of the extension_instances property.

Return Value

Extension[]

Map of DataExtension instances, keyed by classname.

$this setPublicFilesystem(Filesystem $filesystem)

Assign new flysystem backend

Parameters

Filesystem $filesystem

Return Value

$this

Exceptions

InvalidArgumentException

Filesystem getPublicFilesystem()

Get the currently assigned flysystem backend

Return Value

Filesystem

Exceptions

LogicException

$this setProtectedFilesystem(Filesystem $filesystem)

Assign filesystem to use for non-public files

Parameters

Filesystem $filesystem

Return Value

$this

Exceptions

InvalidArgumentException

Filesystem getProtectedFilesystem()

Get filesystem to use for non-public files

Return Value

Filesystem

Exceptions

LogicException

FileResolutionStrategy getPublicResolutionStrategy()

No description

Return Value

FileResolutionStrategy

setPublicResolutionStrategy(FileResolutionStrategy $publicResolutionStrategy)

No description

Parameters

FileResolutionStrategy $publicResolutionStrategy

FileResolutionStrategy getProtectedResolutionStrategy()

No description

Return Value

FileResolutionStrategy

Exceptions

LogicException

setProtectedResolutionStrategy(FileResolutionStrategy $protectedResolutionStrategy)

No description

Parameters

FileResolutionStrategy $protectedResolutionStrategy

protected Filesystem getFilesystemFor(string $fileID) deprecated

deprecated 1.4.0 Use `applyToFileIDOnFilesystem()` instead

Return the store that contains the given fileID

Parameters

string $fileID

Internal file identifier

Return Value

Filesystem

protected mixed applyToFileOnFilesystem(callable $callable, ParsedFileID $parsedFileID, bool $strictHashCheck = true)

Generic method to apply an action to a file regardless of what FileSystem it's on. The action to perform should be provided as a closure expecting the following signature:

function(ParsedFileID $parsedFileID, FileSystem $fs, FileResolutionStrategy $strategy, $visibility)

applyToFileOnFilesystem will try to following steps and call the closure if they are succesfull:

  1. Look for the file on the public filesystem using the explicit fileID provided.
  2. Look for the file on the protected filesystem using the explicit fileID provided.
  3. Look for the file on the public filesystem using the public resolution strategy.
  4. Look for the file on the protected filesystem using the protected resolution strategy.

If the closure returns false, applyToFileOnFilesystem will carry on and try the follow up steps.

Any other value the closure returns (including null) will be returned to the calling function.

Parameters

callable $callable

Action to apply.

ParsedFileID $parsedFileID
bool $strictHashCheck

Return Value

mixed

protected mixed applyToFileIDOnFilesystem(callable $callable, string $fileID, bool $strictHashCheck = true)

Equivalent to applyToFileOnFilesystem, only it expects a `fileID1 string instead of a ParsedFileID.

Parameters

callable $callable

Action to apply.

string $fileID
bool $strictHashCheck

Return Value

mixed

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

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

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

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.

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

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

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

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

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

protected bool deleteFromFilesystem(string $fileID, Filesystem $filesystem) deprecated

deprecated 1.4.0 Use `deleteFromFileStore()` instead

Delete the given file (and any variants) in the given {Filesystem}

Parameters

string $fileID
Filesystem $filesystem

Return Value

bool

True if a file was deleted

protected bool deleteFromFileStore(ParsedFileID $parsedFileID, Filesystem $fs, FileResolutionStrategy $strategy)

Delete the given file (and any variants) in the given {Filesystem}

Parameters

ParsedFileID $parsedFileID
Filesystem $fs
FileResolutionStrategy $strategy

Return Value

bool

protected truncateDirectory(string $dirname, Filesystem $filesystem)

Clear directory if it's empty

Parameters

string $dirname

Name of directory

Filesystem $filesystem

protected Generator findVariants(string $fileID, Filesystem $filesystem) deprecated

deprecated 1.12.0 Use FileResolutionStrategy::findVariants() instead

Returns an iterable {Generator} of all files / variants for the given $fileID in the given $filesystem This includes the empty (no) variant.

Parameters

string $fileID

ID of original file to compare with.

Filesystem $filesystem

Return Value

Generator

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.

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

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 {\SilverStripe\Assets\Storage\grant()} or {\SilverStripe\Assets\Storage\getAsURL()} with $grant = true

Parameters

string $filename

Filename (not including assets)

string $hash

sha1 hash of the file content.

protected moveBetweenFilesystems(string $fileID, Filesystem $from, Filesystem $to) deprecated

deprecated 1.4.0 Use moveBetweenFileStore() instead

Move a file (and its associative variants) between filesystems

Parameters

string $fileID
Filesystem $from
Filesystem $to

protected moveBetweenFileStore(ParsedFileID $parsedFileID, Filesystem $from, FileResolutionStrategy $fromStrategy, Filesystem $to, FileResolutionStrategy $toStrategy, $swap = false)

Move a file and its associated variant from one file store to another adjusting the file name format.

Parameters

ParsedFileID $parsedFileID
Filesystem $from
FileResolutionStrategy $fromStrategy
Filesystem $to
FileResolutionStrategy $toStrategy
$swap

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

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

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.

protected bool isGranted(string|ParsedFileID $fileID)

Determine if a grant exists for the given FileID

Parameters

string|ParsedFileID $fileID

Return Value

bool

protected string getStreamSHA1(resource $stream) deprecated

deprecated 1.4.0 Use FileHashingService::computeFromStream() instead

get sha1 hash from stream

Parameters

resource $stream

Return Value

string

str1 hash

protected string getStreamAsFile(resource $stream)

Get stream as a file

Parameters

resource $stream

Return Value

string

Filename of resulting stream content

Exceptions

Exception

protected bool isSeekableStream(resource $stream)

Determine if this stream is seekable

Parameters

resource $stream

Return Value

bool

True if this stream is seekable

protected array writeWithCallback(callable $callback, string $filename, string $hash, string $variant = null, array $config = [])

Invokes the conflict resolution scheme on the given content, and invokes a callback if the storage request is approved.

Parameters

callable $callback

Will be invoked and passed a fileID if the file should be stored

string $filename

Name for the resulting file

string $hash

SHA1 of the original file content

string $variant

Variant to write

array $config

Write options. {\SilverStripe\Assets\Storage\AssetStore}

Return Value

array

Tuple associative array (Filename, Hash, Variant)

Exceptions

Exception

protected string getDefaultConflictResolution(string $variant)

Choose a default conflict resolution

Parameters

string $variant

Return Value

string

protected bool useLegacyFilenames() deprecated

deprecated 1.4.0 Legacy file names will not be supported in Silverstripe CMS 5

Determine if legacy filenames should be used. This no longuer makes any difference with the introduction of FileResolutionStrategies.

Return Value

bool

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

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

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

protected string|false resolveConflicts(string $conflictResolution, string $fileID)

Determine the path that should be written to, given the conflict resolution scheme

Parameters

string $conflictResolution
string $fileID

Return Value

string|false

Safe filename to write to. If false, then don't write, and use existing file.

Exceptions

InvalidArgumentException

protected AssetNameGenerator fileGeneratorFor(string $fileID)

Get an asset renamer for the given filename.

Parameters

string $fileID

Adapter specific identifier for this file/version

Return Value

AssetNameGenerator

protected string cleanFilename(string $filename) deprecated

deprecated 1.4.0 Use FileIDHelper::cleanFilename() instead

Performs filename cleanup before sending it back.

This name should not contain hash or variants.

Parameters

string $filename

Return Value

string

protected array parseFileID(string $fileID) deprecated

deprecated 1.4.0 Use FileResolutionStrategy::parseFileID() instead

Get Filename and Variant from FileID

Parameters

string $fileID

Return Value

array

protected string getOriginalFilename(string $fileID) deprecated

deprecated 1.4.0 Use FileResolutionStrategy::parseFileID() and ParsedFileID::getFilename() instead

Given a FileID, map this back to the original filename, trimming variant and hash

Parameters

string $fileID

Adapter specific identifier for this file/version

Return Value

string

Filename for this file, omitting hash and variant

protected string getVariant(string $fileID) deprecated

deprecated 1.4.0 Use FileResolutionStrategy::parseFileID() and ParsedFileID::getVariant() instead

Get variant from this file

Parameters

string $fileID

Return Value

string

protected string removeVariant(string $fileID) deprecated

deprecated 1.4.0 Use FileResolutionStrategy::parseFileID() and ParsedFileID::setVariant() instead

Remove variant from a fileID

Parameters

string $fileID

Return Value

string

FileID without variant

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

Map file tuple (hash, name, variant) to a filename to be used by flysystem

The resulting file will look something like my/directory/EA775CB4D4/filename__variant.jpg

Parameters

string $filename

Name of file

string $hash

Hash of original file

string $variant

(if given)

Return Value

string

Adapter specific identifier for this file/version

static flush()

Ensure each adapter re-generates its own server configuration files

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

protected HTTPResponse createResponseFor(Filesystem $flysystem, string $fileID)

Generate an {HTTPResponse} for the given file from the source filesystem

Parameters

Filesystem $flysystem
string $fileID

Return Value

HTTPResponse

protected HTTPResponse createDeniedResponse()

Generate a response for requests to a denied protected file

Return Value

HTTPResponse

protected HTTPResponse createMissingResponse()

Generate a response for missing file requests

Return Value

HTTPResponse

protected HTTPResponse createErrorResponse(int $code)

Create a response with the given error code

Parameters

int $code

Return Value

HTTPResponse

normalisePath($fileID)

No description

Parameters

$fileID

normalise($filename, $hash)

No description

Parameters

$filename
$hash