class AssetCache implements AssetInterface

Caches an asset to avoid the cost of loading and dumping.

Properties

private $asset
private $cache

Methods

__construct(AssetInterface $asset, CacheInterface $cache)

No description

ensureFilter(FilterInterface $filter)

Ensures the current asset includes the supplied filter.

array
getFilters()

Returns an array of filters currently applied.

clearFilters()

Clears all filters from the current asset.

load(FilterInterface $additionalFilter = null)

Loads the asset into memory and applies load filters.

string
dump(FilterInterface $additionalFilter = null)

Applies dump filters and returns the asset as a string.

string
getContent()

Returns the loaded content of the current asset.

setContent(string $content)

Sets the content of the current asset.

string|null
getSourceRoot()

Returns an absolute path or URL to the source asset's root directory.

string|null
getSourcePath()

Returns the relative path for the source asset.

string|null
getSourceDirectory()

Returns the asset's source directory.

string|null
getTargetPath()

Returns the URL for the current asset.

setTargetPath(string $targetPath)

Sets the URL for the current asset.

int|null
getLastModified()

Returns the time the current asset was last modified.

array
getVars()

Returns an array of variable names for this asset.

setValues(array $values)

Sets the values for the asset's variables.

array
getValues()

Returns the current values for this asset.

static string
getCacheKey(AssetInterface $asset, FilterInterface $additionalFilter = null, string $salt = '')

Returns a cache key for the current asset.

Details

at line 29
__construct(AssetInterface $asset, CacheInterface $cache)

No description

Parameters

AssetInterface $asset
CacheInterface $cache

at line 35
ensureFilter(FilterInterface $filter)

Ensures the current asset includes the supplied filter.

Parameters

FilterInterface $filter

A filter

at line 40
array getFilters()

Returns an array of filters currently applied.

Return Value

array

An array of filters

at line 45
clearFilters()

Clears all filters from the current asset.

at line 50
load(FilterInterface $additionalFilter = null)

Loads the asset into memory and applies load filters.

You may provide an additional filter to apply during load.

Parameters

FilterInterface $additionalFilter

An additional filter

at line 63
string dump(FilterInterface $additionalFilter = null)

Applies dump filters and returns the asset as a string.

You may provide an additional filter to apply during dump.

Dumping an asset should not change its state.

If the current asset has not been loaded yet, it should be automatically loaded at this time.

Parameters

FilterInterface $additionalFilter

An additional filter

Return Value

string

The filtered content of the current asset

at line 76
string getContent()

Returns the loaded content of the current asset.

Return Value

string

The content

at line 81
setContent(string $content)

Sets the content of the current asset.

Filters can use this method to change the content of the asset.

Parameters

string $content

The asset content

at line 86
string|null getSourceRoot()

Returns an absolute path or URL to the source asset's root directory.

This value should be an absolute path to a directory in the filesystem, an absolute URL with no path, or null.

For example:

Return Value

string|null

The asset's root

at line 91
string|null getSourcePath()

Returns the relative path for the source asset.

This value can be combined with the asset's source root (if both are non-null) to get something compatible with file_get_contents().

For example:

  • 'js/main.js'
  • 'main.js'
  • null

Return Value

string|null

The source asset path

at line 96
string|null getSourceDirectory()

Returns the asset's source directory.

The source directory is the directory the asset was located in and can be used to resolve references relative to an asset.

Return Value

string|null

The asset's source directory

at line 101
string|null getTargetPath()

Returns the URL for the current asset.

Return Value

string|null

A web URL where the asset will be dumped

at line 106
setTargetPath(string $targetPath)

Sets the URL for the current asset.

Parameters

string $targetPath

A web URL where the asset will be dumped

at line 111
int|null getLastModified()

Returns the time the current asset was last modified.

Return Value

int|null

A UNIX timestamp

at line 116
array getVars()

Returns an array of variable names for this asset.

Return Value

array

at line 121
setValues(array $values)

Sets the values for the asset's variables.

Parameters

array $values

at line 126
array getValues()

Returns the current values for this asset.

Return Value

array

an array of strings

at line 148
static private string getCacheKey(AssetInterface $asset, FilterInterface $additionalFilter = null, string $salt = '')

Returns a cache key for the current asset.

The key is composed of everything but an asset's content:

  • source root
  • source path
  • target url
  • last modified
  • filters

Parameters

AssetInterface $asset

The asset

FilterInterface $additionalFilter

Any additional filter being applied

string $salt

Salt for the key

Return Value

string

A key for identifying the current asset