interface FileHashingService (View source)

Utility for computing and comparing unique file hash. All $fs parameters can either be:

  • an AssetStore constant VISIBILITY constant or
  • an actual Filesystem object.

Methods

public
string
computeFromStream(resource $stream)

Compute the Hash value of the provided stream.

public
string
computeFromFile(string $fileID, Filesystem|string $fs)

Compute the hash of the provided file

public
bool
compare($hashOne, $hashTwo)

Compare 2 full or partial hashes.

public
bool
isCached()

Whatever computed values should be cached

public
void
enableCache()

Enable caching of computed hash.

public
void
disableCache()

Disable caching of computed hash.

public
void
invalidate($fileID, $fs)

Invlaidate the cache for a specific key.

public
false|string
get(string $fileID, Filesystem|string $fs)

Determined if we have an hash for the provided key and return the hash if present

public
void
set($fileID, $fs, $hash)

Explicitely set the cached hash for the provided key.

public
void
move(string $fromFileID, Filesystem|string $fromFs, string $toFileID, Filesystem|string $toFs = false)

Move the specified hash value to a different cached key.

Details

string computeFromStream(resource $stream)

Compute the Hash value of the provided stream.

Parameters

resource $stream

Return Value

string

string computeFromFile(string $fileID, Filesystem|string $fs)

Compute the hash of the provided file

Parameters

string $fileID
Filesystem|string $fs

Return Value

string

Exceptions

UnableToCheckExistence

bool compare($hashOne, $hashTwo)

Compare 2 full or partial hashes.

Parameters

$hashOne
$hashTwo

Return Value

bool

Exceptions

InvalidArgumentException

bool isCached()

Whatever computed values should be cached

Return Value

bool

void enableCache()

Enable caching of computed hash.

Return Value

void

void disableCache()

Disable caching of computed hash.

Return Value

void

void invalidate($fileID, $fs)

Invlaidate the cache for a specific key.

Parameters

$fileID
$fs

Return Value

void

false|string get(string $fileID, Filesystem|string $fs)

Determined if we have an hash for the provided key and return the hash if present

Parameters

string $fileID
Filesystem|string $fs

Return Value

false|string f

void set($fileID, $fs, $hash)

Explicitely set the cached hash for the provided key.

Parameters

$fileID
$fs
$hash

Return Value

void

void move(string $fromFileID, Filesystem|string $fromFs, string $toFileID, Filesystem|string $toFs = false)

Move the specified hash value to a different cached key.

Parameters

string $fromFileID
Filesystem|string $fromFs
string $toFileID
Filesystem|string $toFs

Return Value

void