Asset Bundle

HashVersionStrategy 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
subpackage

VersionStrategy

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

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
inheritdoc
Return values
string

getVersion()

public getVersion(string $path) : string
Parameters
$path : string
Tags
inheritdoc
Return values
string

setLogger()

public setLogger(LoggerInterface $logger) : void
Parameters
$logger : LoggerInterface
Tags
required

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.

Tags
throws
RuntimeException

in case the file exists but cannot be read

throws
JsonException

in case the manifest is not a valid JSON file

throws
UnexpectedValueException

in case the manifest content has invalid structure


        
On this page

Search results