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

string
computeFromStream(resource $stream)

Compute the Hash value of the provided stream.

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

Compute the hash of the provided file

bool
compare($hashOne, $hashTwo)

Compare 2 full or partial hashes.

bool
isCached()

Whatever computed values should be cached

void
enableCache()

Enable caching of computed hash.

void
disableCache()

Disable caching of computed hash.

void
invalidate($fileID, $fs)

Invlaidate the cache for a specific key.

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

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

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

Explicitely set the cached hash for the provided key.

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

FileNotFoundException

bool compare($hashOne, $hashTwo)

Compare 2 full or partial hashes.

Parameters

$hashOne
$hashTwo

Return Value

bool

Exceptions

InvalidArgumentException

if one of the hash is an empty string

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