class AssetFactory

The asset factory creates asset objects.

Properties

private $root
private $debug
private $output
private $workers
private $am
private $fm

Methods

__construct(string $root, bool $debug = false)

Constructor.

setDebug(bool $debug)

Sets debug mode for the current factory.

bool
isDebug()

Checks if the factory is in debug mode.

setDefaultOutput(string $output)

Sets the default output string.

getAssetManager()

Returns the current asset manager.

setAssetManager(AssetManager $am)

Sets the asset manager to use when creating asset references.

getFilterManager()

Returns the current filter manager.

setFilterManager(FilterManager $fm)

Sets the filter manager to use when adding filters.

createAsset(array|string $inputs = [], array|string $filters = [], array $options = [])

Creates a new asset.

generateAssetName($inputs, $filters, $options = [])

No description

getLastModified(AssetInterface $asset)

No description

parseInput(string $input, array $options = [])

Parses an input string string into an asset.

createAssetCollection(array $assets = [], array $options = [])

No description

createAssetReference($name)

No description

createHttpAsset($sourceUrl, $vars)

No description

createGlobAsset($glob, $root = null, $vars = [])

No description

createFileAsset($source, $root = null, $path = null, $vars = [])

No description

getFilter($name)

No description

applyWorkers(AssetCollectionInterface $asset)

Filters an asset collection through the factory workers.

static 
isAbsolutePath($path)

No description

static string|null
findRootDir(string $path, array $roots)

Loops through the root directories and returns the first match.

Details

at line 50
__construct(string $root, bool $debug = false)

Constructor.

Parameters

string $root

The default root directory

bool $debug

Filters prefixed with a "?" will be omitted in debug mode

at line 63
setDebug(bool $debug)

Sets debug mode for the current factory.

Parameters

bool $debug

Debug mode

at line 73
bool isDebug()

Checks if the factory is in debug mode.

Return Value

bool

Debug mode

at line 83
setDefaultOutput(string $output)

Sets the default output string.

Parameters

string $output

The default output string

at line 93
AssetManager|null getAssetManager()

Returns the current asset manager.

Return Value

AssetManager|null

The asset manager

at line 103
setAssetManager(AssetManager $am)

Sets the asset manager to use when creating asset references.

Parameters

AssetManager $am

The asset manager

at line 113
FilterManager|null getFilterManager()

Returns the current filter manager.

Return Value

FilterManager|null

The filter manager

at line 123
setFilterManager(FilterManager $fm)

Sets the filter manager to use when adding filters.

Parameters

FilterManager $fm

The filter manager

at line 147
AssetCollection createAsset(array|string $inputs = [], array|string $filters = [], array $options = [])

Creates a new asset.

Prefixing a filter name with a question mark will cause it to be omitted when the factory is in debug mode.

Available options:

  • output: An output string
  • name: An asset name for interpolation in output patterns
  • debug: Forces debug mode on or off for this asset
  • root: An array or string of more root directories

Parameters

array|string $inputs

An array of input strings

array|string $filters

An array of filter names

array $options

An array of options

Return Value

AssetCollection

An asset collection

at line 237
generateAssetName($inputs, $filters, $options = [])

No description

Parameters

$inputs
$filters
$options

at line 248
getLastModified(AssetInterface $asset)

No description

Parameters

AssetInterface $asset

at line 300
protected AssetInterface parseInput(string $input, array $options = [])

Parses an input string string into an asset.

The input string can be one of the following:

  • A reference: If the string starts with an "at" sign it will be interpreted as a reference to an asset in the asset manager
  • An absolute URL: If the string contains "://" or starts with "//" it will be interpreted as an HTTP asset
  • A glob: If the string contains a "*" it will be interpreted as a glob
  • A path: Otherwise the string is interpreted as a filesystem path

Both globs and paths will be absolutized using the current root directory.

Parameters

string $input

An input string

array $options

An array of options

Return Value

AssetInterface

An asset

at line 331
protected createAssetCollection(array $assets = [], array $options = [])

No description

Parameters

array $assets
array $options

at line 336
protected createAssetReference($name)

No description

Parameters

$name

at line 345
protected createHttpAsset($sourceUrl, $vars)

No description

Parameters

$sourceUrl
$vars

at line 350
protected createGlobAsset($glob, $root = null, $vars = [])

No description

Parameters

$glob
$root
$vars

at line 355
protected createFileAsset($source, $root = null, $path = null, $vars = [])

No description

Parameters

$source
$root
$path
$vars

at line 360
protected getFilter($name)

No description

Parameters

$name

at line 379
private AssetCollectionInterface applyWorkers(AssetCollectionInterface $asset)

Filters an asset collection through the factory workers.

Each leaf asset will be processed first, followed by the asset collection itself.

Parameters

AssetCollectionInterface $asset

An asset collection

Return Value

AssetCollectionInterface

at line 402
static private isAbsolutePath($path)

No description

Parameters

$path

at line 415
static private string|null findRootDir(string $path, array $roots)

Loops through the root directories and returns the first match.

Parameters

string $path

An absolute path

array $roots

An array of root directories

Return Value

string|null

The matching root directory, if found