AssetFactory
in package
The asset factory creates asset objects.
Tags
Table of Contents
- $am : mixed
- $debug : mixed
- $fm : mixed
- $output : mixed
- $root : mixed
- $workers : mixed
- __construct() : mixed
- Constructor.
- addWorker() : mixed
- Adds a factory worker.
- createAsset() : AssetCollection
- Creates a new asset.
- generateAssetName() : mixed
- getAssetManager() : AssetManager|null
- Returns the current asset manager.
- getFilterManager() : FilterManager|null
- Returns the current filter manager.
- getLastModified() : mixed
- isDebug() : bool
- Checks if the factory is in debug mode.
- setAssetManager() : mixed
- Sets the asset manager to use when creating asset references.
- setDebug() : mixed
- Sets debug mode for the current factory.
- setDefaultOutput() : mixed
- Sets the default output string.
- setFilterManager() : mixed
- Sets the filter manager to use when adding filters.
- createAssetCollection() : mixed
- createAssetReference() : mixed
- createFileAsset() : mixed
- createGlobAsset() : mixed
- createHttpAsset() : mixed
- getFilter() : mixed
- parseInput() : AssetInterface
- Parses an input string string into an asset.
- applyWorkers() : AssetCollectionInterface
- Filters an asset collection through the factory workers.
- findRootDir() : string|null
- Loops through the root directories and returns the first match.
- isAbsolutePath() : mixed
Properties
$am
private
mixed
$am
$debug
private
mixed
$debug
$fm
private
mixed
$fm
$output
private
mixed
$output
$root
private
mixed
$root
$workers
private
mixed
$workers
Methods
__construct()
Constructor.
public
__construct(string $root[, bool $debug = false ]) : mixed
Parameters
- $root : string
-
The default root directory
- $debug : bool = false
-
Filters prefixed with a "?" will be omitted in debug mode
Return values
mixed —addWorker()
Adds a factory worker.
public
addWorker(WorkerInterface $worker) : mixed
Parameters
- $worker : WorkerInterface
-
A worker
Return values
mixed —createAsset()
Creates a new asset.
public
createAsset([array<string|int, mixed>|string $inputs = array() ][, array<string|int, mixed>|string $filters = array() ][, array<string|int, mixed> $options = array() ]) : AssetCollection
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
- $inputs : array<string|int, mixed>|string = array()
-
An array of input strings
- $filters : array<string|int, mixed>|string = array()
-
An array of filter names
- $options : array<string|int, mixed> = array()
-
An array of options
Return values
AssetCollection —An asset collection
generateAssetName()
public
generateAssetName(mixed $inputs, mixed $filters[, mixed $options = array() ]) : mixed
Parameters
- $inputs : mixed
- $filters : mixed
- $options : mixed = array()
Return values
mixed —getAssetManager()
Returns the current asset manager.
public
getAssetManager() : AssetManager|null
Return values
AssetManager|null —The asset manager
getFilterManager()
Returns the current filter manager.
public
getFilterManager() : FilterManager|null
Return values
FilterManager|null —The filter manager
getLastModified()
public
getLastModified(AssetInterface $asset) : mixed
Parameters
- $asset : AssetInterface
Return values
mixed —isDebug()
Checks if the factory is in debug mode.
public
isDebug() : bool
Return values
bool —Debug mode
setAssetManager()
Sets the asset manager to use when creating asset references.
public
setAssetManager(AssetManager $am) : mixed
Parameters
- $am : AssetManager
-
The asset manager
Return values
mixed —setDebug()
Sets debug mode for the current factory.
public
setDebug(bool $debug) : mixed
Parameters
- $debug : bool
-
Debug mode
Return values
mixed —setDefaultOutput()
Sets the default output string.
public
setDefaultOutput(string $output) : mixed
Parameters
- $output : string
-
The default output string
Return values
mixed —setFilterManager()
Sets the filter manager to use when adding filters.
public
setFilterManager(FilterManager $fm) : mixed
Parameters
- $fm : FilterManager
-
The filter manager
Return values
mixed —createAssetCollection()
protected
createAssetCollection([array<string|int, mixed> $assets = array() ][, array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $assets : array<string|int, mixed> = array()
- $options : array<string|int, mixed> = array()
Return values
mixed —createAssetReference()
protected
createAssetReference(mixed $name) : mixed
Parameters
- $name : mixed
Return values
mixed —createFileAsset()
protected
createFileAsset(mixed $source[, mixed $root = null ][, mixed $path = null ], mixed $vars) : mixed
Parameters
- $source : mixed
- $root : mixed = null
- $path : mixed = null
- $vars : mixed
Return values
mixed —createGlobAsset()
protected
createGlobAsset(mixed $glob[, mixed $root = null ], mixed $vars) : mixed
Parameters
- $glob : mixed
- $root : mixed = null
- $vars : mixed
Return values
mixed —createHttpAsset()
protected
createHttpAsset(mixed $sourceUrl, mixed $vars) : mixed
Parameters
- $sourceUrl : mixed
- $vars : mixed
Return values
mixed —getFilter()
protected
getFilter(mixed $name) : mixed
Parameters
- $name : mixed
Return values
mixed —parseInput()
Parses an input string string into an asset.
protected
parseInput(string $input[, array<string|int, mixed> $options = array() ]) : AssetInterface
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
- $input : string
-
An input string
- $options : array<string|int, mixed> = array()
-
An array of options
Return values
AssetInterface —An asset
applyWorkers()
Filters an asset collection through the factory workers.
private
applyWorkers(AssetCollectionInterface $asset) : AssetCollectionInterface
Each leaf asset will be processed first, followed by the asset collection itself.
Parameters
- $asset : AssetCollectionInterface
-
An asset collection
Return values
AssetCollectionInterface —findRootDir()
Loops through the root directories and returns the first match.
private
static findRootDir(string $path, array<string|int, mixed> $roots) : string|null
Parameters
- $path : string
-
An absolute path
- $roots : array<string|int, mixed>
-
An array of root directories
Return values
string|null —The matching root directory, if found
isAbsolutePath()
private
static isAbsolutePath(mixed $path) : mixed
Parameters
- $path : mixed