PHP Class MiniAsset\AssetConfig

Mostra file Open project: markstory/mini-asset Class Usage Examples

Protected Properties

Property Type Description
$_data array Parsed configuration data.
$_defaults array These defaults are used unless a key is redefined.
$_extensionTypes array handle.
$_filters array Filter configuration
$_modifiedTime integer The max modified time of all the config files loaded.
$_targets array Target configuration
$constantMap array A hash of constants that can be expanded when reading ini files.

Public Methods

Method Description
__construct ( array $data = [], array $constants = [] ) Constructor, set some initial data for a AssetConfig object.
addExtension ( string $ext, array $config ) : void Add/Replace an extension configuration.
addTarget ( string $target, array $config ) Create a new build target.
allFilters ( ) : array Get configuration for all filters.
buildFromIniFile ( string $iniFile = null, $constants = [] ) Factory method
cachePath ( string $ext, string $path = null ) Accessor for getting the cachePath for a given extension.
constants ( ) : array Get the list of loaded constants.
extensions ( ) : array Get the list of extensions this config object supports.
files ( string $target ) : array Get the list of files that match the given build file.
filterConfig ( string $filter, array $settings = null ) : mixed. Get/Set filter Settings.
filters ( string $ext, array $filters = null ) : array Get/set filters for an extension
general ( string $key, mixed $value = null ) : mixed Get / set values from the General section. This is preferred to using get()/set() as you don't run the risk of making a mistake in General's casing.
get ( string $path ) Get values from the config data.
getExt ( string $file ) : string Get the extension for a filename.
hasTarget ( string $name ) : boolean Check if the named target exists.
isThemed ( string $target ) : boolean Check if a build target is themed.
load ( string $path, string $prefix = '' ) Load a config file into the current instance.
modifiedTime ( ) : integer Get the modified time of the loaded configuration files.
paths ( string $ext, string $target = null, array $paths = null ) : array Get/set paths for an extension. Setting paths will replace global or per target existing paths. Its only intended for testing.
requires ( string $target ) : array Get the required build targets for this target.
set ( string $path, string $value ) Set values into the config object, You can't modify targets, or filters with this. Use the appropriate methods for those settings.
targetFilters ( string $name ) : array Get the filters for a build target.
targets ( ) : array Get the build targets.
theme ( string $theme = null ) : mixed Set the active theme for building assets.

Protected Methods

Method Description
_addConstants ( array $constants ) : void Add path based constants to the mapped constants.
_parseExtensionDef ( $target ) : array Parses paths in an extension definition
_replacePathConstants ( string $path ) : string Replaces the file path constants used in Config files.
readConfig ( string $filename ) : array Read the configuration file from disk
resolveExtends ( ) : void Once all targets have been built, resolve extend options.

Method Details

__construct() public method

Any userland constants that resolve to file paths will automatically be added to the constants available in configuration files.
public __construct ( array $data = [], array $constants = [] )
$data array Initial data set for the object.
$constants array Additional constants that will be translated when parsing paths.

_addConstants() protected method

Add path based constants to the mapped constants.
protected _addConstants ( array $constants ) : void
$constants array The constants to map
return void

_parseExtensionDef() protected method

Parses paths in an extension definition
protected _parseExtensionDef ( $target ) : array
return array Array of build extension information with paths replaced.

_replacePathConstants() protected method

Will replace APP and WEBROOT
protected _replacePathConstants ( string $path ) : string
$path string Path to replace constants on
return string constants replaced

addExtension() public method

Add/Replace an extension configuration.
public addExtension ( string $ext, array $config ) : void
$ext string Extension name
$config array Configuration for the extension
return void

addTarget() public method

Create a new build target.
public addTarget ( string $target, array $config )
$target string Name of the target file. The extension will be inferred based on the last extension.
$config array Config data for the target. Should contain files, filters and theme key.

allFilters() public method

Useful for building FilterRegistry objects
public allFilters ( ) : array
return array Config data related to all filters.

buildFromIniFile() public static method

Factory method
Deprecation: Use ConfigFinder::loadAll() instead.
public static buildFromIniFile ( string $iniFile = null, $constants = [] )
$iniFile string File path for the ini file to parse.

cachePath() public method

Accessor for getting the cachePath for a given extension.
public cachePath ( string $ext, string $path = null )
$ext string Extension to get paths for.
$path string The path to cache files using $ext to.

constants() public method

Get the list of loaded constants.
public constants ( ) : array
return array

extensions() public method

Get the list of extensions this config object supports.
public extensions ( ) : array
return array Extension list.

files() public method

Get the list of files that match the given build file.
public files ( string $target ) : array
$target string The build file with extension.
return array An array of files for the chosen build.

filterConfig() public method

Get/Set filter Settings.
public filterConfig ( string $filter, array $settings = null ) : mixed.
$filter string The filter name
$settings array The settings to set, leave null to get
return mixed.

filters() public method

Get/set filters for an extension
public filters ( string $ext, array $filters = null ) : array
$ext string Name of an extension
$filters array Filters to replace either the global or per target filters.
return array Filters for extension.

general() public method

Get / set values from the General section. This is preferred to using get()/set() as you don't run the risk of making a mistake in General's casing.
public general ( string $key, mixed $value = null ) : mixed
$key string The key to read/write
$value mixed The value to set.
return mixed Null when writing. Either a value or null when reading.

get() public method

Get values from the config data.
public get ( string $path )
$path string The path you want.

getExt() public method

Get the extension for a filename.
public getExt ( string $file ) : string
$file string
return string

hasTarget() public method

Check if the named target exists.
public hasTarget ( string $name ) : boolean
$name string The name of the target to check.
return boolean

isThemed() public method

Check if a build target is themed.
public isThemed ( string $target ) : boolean
$target string A build target.
return boolean

load() public method

Load a config file into the current instance.
public load ( string $path, string $prefix = '' )
$path string The config file to load.
$prefix string The string to prefix all targets in $path with.

modifiedTime() public method

Get the modified time of the loaded configuration files.
public modifiedTime ( ) : integer
return integer

paths() public method

Get/set paths for an extension. Setting paths will replace global or per target existing paths. Its only intended for testing.
public paths ( string $ext, string $target = null, array $paths = null ) : array
$ext string Extension to get paths for.
$target string A build target. If provided the target's paths (if any) will also be returned.
$paths array Paths to replace either the global or per target paths.
return array An array of paths to search for assets on.

readConfig() protected method

Read the configuration file from disk
protected readConfig ( string $filename ) : array
$filename string Name of the inifile to parse
return array Inifile contents

requires() public method

Required builds differ from extends in that the compiled asset is merged into the named target. In extends, the source files & filter for an asset are merged into a target.
public requires ( string $target ) : array
$target string The target to get requirements for.
return array A list of required builds.

resolveExtends() protected method

Once all targets have been built, resolve extend options.
protected resolveExtends ( ) : void
return void

set() public method

Set values into the config object, You can't modify targets, or filters with this. Use the appropriate methods for those settings.
public set ( string $path, string $value )
$path string The path to set.
$value string The value to set.

targetFilters() public method

Get the filters for a build target.
public targetFilters ( string $name ) : array
$name string The build target to get filters for.
return array

targets() public method

Get the build targets.
public targets ( ) : array
return array An array of build targets.

theme() public method

Set the active theme for building assets.
public theme ( string $theme = null ) : mixed
$theme string The theme name to set. Null to get
return mixed Either null on set, or theme on get

Property Details

$_data protected_oe property

Parsed configuration data.
protected array $_data
return array

$_defaults protected_oe static_oe property

These defaults are used unless a key is redefined.
protected static array $_defaults
return array

$_extensionTypes protected_oe static_oe property

handle.
protected static array $_extensionTypes
return array

$_filters protected_oe property

Filter configuration
protected array $_filters
return array

$_modifiedTime protected_oe property

The max modified time of all the config files loaded.
protected int $_modifiedTime
return integer

$_targets protected_oe property

Target configuration
protected array $_targets
return array

$constantMap protected_oe property

A hash of constants that can be expanded when reading ini files.
protected array $constantMap
return array