TestAssetStore
class TestAssetStore extends FlysystemAssetStore implements TestOnly (View source)
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.
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 | 
| keep_empty_dirs | bool | Flag if empty folders are allowed. | from FlysystemAssetStore | 
| denied_response_code | int | Enable disclosure of secure assets | |
| missing_response_code | int | Set HTTP error code to use for missing secure assets | from FlysystemAssetStore | 
| redirect_response_code | int | Define the HTTP Response code for request that should be temporarily redirected to a different URL. Defaults to 302. | from FlysystemAssetStore | 
| permanent_redirect_response_code | int | Define the HTTP Response code for request that should be permanently redirected to a different URL. Defaults to 301. | from FlysystemAssetStore | 
| file_response_headers | array | Custom headers to add to all custom file responses | from FlysystemAssetStore | 
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 public 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 | 
| public static | null|bool | $seekable_override | Set to true|false to override all isSeekableStream calls | |
| public static | string | $basedir | Base dir of current file | 
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
Adds any methods from Extension instances attached to this object.
Register an callback to invoke that defines extra methods
Return TRUE if a method exists on this object
Determines if a custom method with this name is defined.
Get meta-data details on a named method
Return the names of all the methods available on this object
Get all public built in methods for this class
Find all methods on the given object.
Add all the methods from an object property.
Add all the methods from an object property (which is an Extension) to this object.
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)
Add callback as a method.
Allows user code to hook into Object::extend prior to control being delegated to extensions. Each callback will be reset once called.
Allows user code to hook into Object::extend after control being delegated to extensions. Each callback will be reset once called.
Adds any methods from Extension instances attached to 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 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 $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.
Get all extension instances for this specific object instance.
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)Equivalent to applyToFileOnFilesystem, only it expects a `fileID1 string instead of a ParsedFileID.
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
Delete the given file (and any variants) in the given {Filesystem}
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.
Move a file and its associated variant from one file store to another adjusting the file name format.
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.
Invokes the conflict resolution scheme on the given content, and invokes a callback if the storage request is approved.
Get metadata for this file, if available
Get mime type of this file
Determine if a file exists with the given tuple
Determine the path that should be written to, given the conflict resolution scheme
Get an asset renamer for the given filename.
Map file tuple (hash, name, variant) to a filename to be used by flysystem
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.
Generate an {HTTPResponse} for the given file from the source filesystem
Generate a response for requests to a denied protected file
Generate a response for missing file requests
Create a response with the given error code
Helper method to get local filesystem path for this file
Details
        
                static            Config_ForClass
    config()
        
    
    Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
        
                            mixed
    uninherited(string $name)
        
    
    Gets the uninherited value for the given config option
        
                            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()
        
                    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
        
                            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
        
                    protected        bool
    hasCustomMethod($method)
        
    
    Determines if a custom method with this name is defined.
        
                    protected        array
    getExtraMethodConfig(string $method)
        
    
    Get meta-data details on a named method
        
                            array
    allMethodNames(bool $custom = false)
        
    
    Return the names of all the methods available on this object
        
                static    protected        array
    findBuiltInMethods(string|object $class = null)
        
    
    Get all public built in methods for this class
        
                    protected        array
    findMethodsFrom(object $object)
        
    
    Find all methods on the given object.
        
                    protected        
    addMethodsFrom(string $property, string|int $index = null)
        
    
    Add all the methods from an object property.
        
                    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        
    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()).
        
                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.
        
                static            array
    get_extensions(string $class = null, bool $includeArgumentString = false)
        
    
    No description
        
                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 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 __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 $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(
        
                            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.
        
                            $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
        
                            FileResolutionStrategy
    getPublicResolutionStrategy()
        
    
    No description
        
                            
    setPublicResolutionStrategy(FileResolutionStrategy $publicResolutionStrategy)
        
    
    No description
        
                            FileResolutionStrategy
    getProtectedResolutionStrategy()
        
    
    No description
        
                            
    setProtectedResolutionStrategy(FileResolutionStrategy $protectedResolutionStrategy)
        
    
    No description
        
                    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:
- Look for the file on the public filesystem using the explicit fileID provided.
- Look for the file on the protected filesystem using the explicit fileID provided.
- Look for the file on the public filesystem using the public resolution strategy.
- 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.
        
                    protected        mixed
    applyToFileIDOnFilesystem(callable $callable, string $fileID, bool $strictHashCheck = true)
        
    
    Equivalent to applyToFileOnFilesystem, only it expects a `fileID1 string instead of a ParsedFileID.
        
                            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
        
                    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
        
                            
    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 {\SilverStripe\Assets\Storage\grant()} or {\SilverStripe\Assets\Storage\getAsURL()} with $grant = true
        
                    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.
        
                            
    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.
        
                            bool
    isGranted(string|ParsedFileID $fileID)
        
    
    Allows testing of grant status
        
                    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.
        
                            string
    getDefaultConflictResolution(string $variant)
        
    
    Choose a default conflict resolution
        
                            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
        
                    protected        string|false
    resolveConflicts(string $conflictResolution, string $fileID)
        
    
    Determine the path that should be written to, given the conflict resolution scheme
        
                    protected        AssetNameGenerator
    fileGeneratorFor(string $fileID)
        
    
    Get an asset renamer for the given filename.
        
                            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
        
                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.
        
                    protected        HTTPResponse
    createResponseFor(Filesystem $flysystem, string $fileID)
        
    
    Generate an {HTTPResponse} for the given file from the source filesystem
        
                    protected        HTTPResponse
    createDeniedResponse()
        
    
    Generate a response for requests to a denied protected file
        
                    protected        HTTPResponse
    createMissingResponse()
        
    
    Generate a response for missing file requests
        
                    protected        HTTPResponse
    createErrorResponse(int $code)
        
    
    Create a response with the given error code
        
                            
    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, bool $forceProtected = false, bool $relative = false)
        
    
    Helper method to get local filesystem path for this file
        
                            
    cleanFilename(string $filename)
        
    
    No description
        
                            
    parseFileID(string $fileID)
        
    
    No description
        
                            
    getOriginalFilename(string $fileID)
        
    
    No description
        
                            
    getFilesystemFor(string $fileID)
        
    
    No description
        
                            
    removeVariant(string $fileID)
        
    
    No description