class HashFileIDHelper implements FileIDHelper (View source)

Parsed Hash path URLs. Hash paths group a file and its variant under a directory based on a hash generated from the content of the original file.

Hash paths are used by the Protected asset adapter and was the default for the public adapter prior to SilverStripe 4.4.

e.g.: Uploads/a1312bc34d/sam__ResizedImageWzYwLDgwXQ.jpg

Traits

A class that can be instantiated or replaced via DI

Constants

HASH_TRUNCATE_LENGTH

Default length at which hashes are truncated.

Methods

public static 
create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

public static 
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

public
string
buildFileID(string|ParsedFileID $filename, string $hash = null, string $variant = null, bool $cleanfilename = true)

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

public
string
cleanFilename(string $filename)

Clean up filename to remove constructs that might clash with the underlying path format of this FileIDHelper.

public
parseFileID(string $fileID)

Get Filename, Variant and Hash from a fileID. If a FileID can not be parsed, returns null.

public
bool
isVariantOf(string $fileID, ParsedFileID $original)

Determine if the provided fileID is a variant of $parsedFileID.

public
string
lookForVariantIn(ParsedFileID $parsedFileID)

Compute the relative path where variants of the provided parsed file ID are expected to be stored.

public
bool
lookForVariantRecursive()

Specify if this File ID Helper stores variants in subfolders and require a recursive look up to find all variants.

Details

static Injectable create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();

Parameters

mixed ...$args

Return Value

Injectable

static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

string buildFileID(string|ParsedFileID $filename, string $hash = null, string $variant = null, bool $cleanfilename = true)

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

Parameters

string|ParsedFileID $filename

Name of file or ParsedFileID object

string $hash

Hash of original file

string $variant

(if given)

bool $cleanfilename

Whether the filename should be cleaned before building the file ID. Defaults to true.

Return Value

string

Adapter specific identifier for this file/version

string cleanFilename(string $filename)

Clean up filename to remove constructs that might clash with the underlying path format of this FileIDHelper.

Parameters

string $filename

Return Value

string

ParsedFileID|null parseFileID(string $fileID)

Get Filename, Variant and Hash from a fileID. If a FileID can not be parsed, returns null.

Parameters

string $fileID

Return Value

ParsedFileID|null

bool isVariantOf(string $fileID, ParsedFileID $original)

Determine if the provided fileID is a variant of $parsedFileID.

Parameters

string $fileID
ParsedFileID $original

Return Value

bool

string lookForVariantIn(ParsedFileID $parsedFileID)

Compute the relative path where variants of the provided parsed file ID are expected to be stored.

Parameters

ParsedFileID $parsedFileID

Return Value

string

bool lookForVariantRecursive()

Specify if this File ID Helper stores variants in subfolders and require a recursive look up to find all variants.

Return Value

bool