HashVersionStrategy
in package
implements
VersionStrategyInterface, LoggerAwareInterface
FinalYes
Asset version strategy.
This version strategy reads asset hashes from a JSON manifest file and appends them as a query parameter to their path. The manifest file must be a JSON map where keys are asset paths and values their hashes. Asset paths must not begin with a slash.
Tags
Table of Contents
Interfaces
- VersionStrategyInterface
- LoggerAwareInterface
Constants
- PATH_FORMAT = '%s?v=%s'
- `sprintf` format for asset path with version.
Properties
- $hashes : array<string, string>|null
- Asset hashes.
- $logger : LoggerInterface|null
- $manifestPath : string
- Manifest file path.
Methods
- __construct() : mixed
- HashVersionStrategy constructor.
- applyVersion() : string
- getVersion() : string
- setLogger() : void
- getHash() : string|null
- Returns file hash.
- loadManifest() : void
- Loads file hashes from the manifest file.
Constants
PATH_FORMAT
`sprintf` format for asset path with version.
private
mixed
PATH_FORMAT
= '%s?v=%s'
Properties
$hashes
Asset hashes.
private
array<string, string>|null
$hashes
= null
$logger
private
LoggerInterface|null
$logger
= null
$manifestPath
Manifest file path.
private
string
$manifestPath
Methods
__construct()
HashVersionStrategy constructor.
public
__construct(string $manifestPath) : mixed
Parameters
- $manifestPath : string
-
path to manifest file
applyVersion()
public
applyVersion(string $path) : string
Parameters
- $path : string
Tags
Return values
stringgetVersion()
public
getVersion(string $path) : string
Parameters
- $path : string
Tags
Return values
stringsetLogger()
public
setLogger(LoggerInterface $logger) : void
Parameters
- $logger : LoggerInterface
Tags
getHash()
Returns file hash.
private
getHash(string $key) : string|null
Parameters
- $key : string
-
file path
Return values
string|null —hash or null
if not set
loadManifest()
Loads file hashes from the manifest file.
private
loadManifest() : void
Produces an error log entry if the manifest file does not exist and sets the hash map to an empty array.