FlysystemAssetStore
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 |
Properties
static private array | $extensions | An array of extension names and parameters to be applied to this object upon construction. |
from Extensible |
static private bool | $legacy_filenames | Enable to use legacy filename behaviour (omits hash and uses the natural filename). |
|
static private bool | $keep_empty_dirs | Flag if empty folders are allowed. |
|
static private int | $denied_response_code | Set HTTP error code for requests to secure denied assets. |
|
static private int | $missing_response_code | Set HTTP error code to use for missing secure assets |
|
static private int | $redirect_response_code | Define the HTTP Response code for request that should be temporarily redirected to a different URL. Defaults to 302. |
|
static private int | $permanent_redirect_response_code | Define the HTTP Response code for request that should be permanently redirected to a different URL. Defaults to 301. |
|
static private array | $file_response_headers | Custom headers to add to all custom file responses |
Methods
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
Gets the uninherited value for the given config option
Attempts to locate and call a method dynamically added to a class at runtime if a default cannot be located
Return the names of all the methods available on this object
Add an extension to a specific class.
No description
Get extra config sources for this class
Return TRUE if a class has a specified extension.
Calls a method if available on both this object and all applied {@link Extensions}, and then attempts to merge all results into an array
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
Get an extension instance attached to this object by name.
Returns TRUE if this object instance has a specific extension applied in {@link $extension_instances}. Extension instances are initialized at constructor time, meaning if you use {@link add_extension()} afterwards, the added extension will just be added to new instances of the extended class. Use the static method {@link has_extension()} to check if a class (not an instance) has a specific extension.
Get all extension instances for this specific object instance.
Assign new flysystem backend
Get the currently assigned flysystem backend
Assign filesystem to use for non-public files
Get filesystem to use for non-public files
Return list of feature capabilities of this backend as an array.
Determine visibility of the given file
Get a stream for this file
Get contents of a given file
Get the url for the file
Assign a local file to the backend.
Assign a set of data to the backend
Assign a stream to the backend
Delete a file (and all variants) identified by the given filename and hash
Rename a file (and all variants) to a new filename
Copy a file (and all variants) to a new filename
Publicly expose the file (and all variants) identified by the given filename and hash
Similar to publish, only any existing files that would be overriden by publishing will be moved back to the protected store.
Protect a file (and all variants) from public access, identified by the given filename and hash.
Ensures that access to the specified protected file is granted for the current user.
Revoke access to the given file for the current user.
Check if the current user can view the given file.
Get metadata for this file, if available
Get mime type of this file
Determine if a file exists with the given tuple
Ensure each adapter re-generates its own server configuration files
Generate a custom HTTP response for a request to a given asset, identified by a path.
No description
No description
Details
static Config_ForClass
config()
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
mixed
stat(string $name)
deprecated
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
deprecated
Update the config value for a given property
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 {@link Extensions}, {@link Object::createMethod()} or {@link Object::addWrapperMethod()}
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
array
allMethodNames(bool $custom = false)
Return the names of all the methods available on this object
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 {@link Object::$extensions} array. See {@link 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 {@link singleton()}).
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 {@link Object} instances which are already created, but will have an effect on new extensions. Clears any previously created singletons through {@link singleton()} to avoid side-effects from stale extension information.
static array
get_extensions(string $class = null, bool $includeArgumentString = false)
static array|null
get_extra_config_sources(string $class = null)
Get extra config sources for this class
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))
array
invokeWithExtensions(string $method, mixed ...$arguments)
Calls a method if available on both this object and all applied {@link Extensions}, and then attempts to merge all results into an array
array
extend(string $method, mixed ...$arguments)
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 {@link __construct()} in {@link defineMethods()}.
Extension|null
getExtensionInstance(string $extension)
Get an extension instance attached to this object by name.
bool
hasExtension(string $extension)
Returns TRUE if this object instance has a specific extension applied in {@link $extension_instances}. Extension instances are initialized at constructor time, meaning if you use {@link add_extension()} afterwards, the added extension will just be added to new instances of the extended class. Use the static method {@link has_extension()} to check if a class (not an instance) has a specific extension.
Caution: Don't use singleton(
Extension[]
getExtensionInstances()
Get all extension instances for this specific object instance.
See {@link 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.
$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.
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).
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 = [])
Assign a local file to the backend.
array
setFromString(string $data, string $filename, string $hash = null, string $variant = null, array $config = [])
Assign a set of data to the backend
array
setFromStream(resource $stream, string $filename, string $hash = null, string $variant = null, array $config = [])
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.
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 \SilverStripe\Assets\Storage\grant()} or {see \SilverStripe\Assets\Storage\getAsURL()} with $grant = true
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.
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
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
HTTPResponse
getResponseFor(string $asset)
Generate a custom HTTP response for a request to a given asset, identified by a path.