public static assets ( string $type = null, array $options = [] ) : array | ||
$type | string | The name of the asset type, i.e. `'js'` or `'css'`. |
$options | array | If registering a new asset type or modifying an existing asset type, contains settings for the asset type, where the available keys are as follows: - `'suffix'`: The standard suffix for this content type, with leading dot ('.') if applicable. - `'filter'`: An array of key/value pairs representing simple string replacements to be done on a path once it is generated. - `'paths'`: An array of key/value pairs where the keys are `String::insert()` compatible paths, and the values are array lists of keys to be inserted into the path string. |
return | array | If `$type` is empty, an associative array of all registered types and all associated options is returned. If `$type` is a string and `$options` is empty, returns an associative array with the options for `$type`. If `$type` and `$options` are both non-empty, returns `null`. |
public static function assets($type = null, $options = array())
{
$defaults = array('suffix' => null, 'filter' => null, 'paths' => array());
if (!$type) {
return static::_assets();
}
if ($options === false) {
unset(static::$_assets[$type]);
}
if (!$options) {
return static::_assets($type);
}
$options = (array) $options + $defaults;
if ($base = static::_assets($type)) {
$options = array_merge($base, array_filter($options));
}
static::$_assets[$type] = $options;
}
public function testCustomAssetPathGeneration() { Media::assets('my', array('suffix' => '.my', 'path' => array('{:base}/my/{:path}' => array('base', 'path')))); $result = Media::asset('subpath/file', 'my'); $expected = '/my/subpath/file.my'; $this->assertEqual($expected, $result); Media::assets('my', array('filter' => array('/my/' => '/your/'))); $result = Media::asset('subpath/file', 'my'); $expected = '/your/subpath/file.my'; $this->assertEqual($expected, $result); $result = Media::asset('subpath/file', 'my', array('base' => '/app/path')); $expected = '/app/path/your/subpath/file.my'; $this->assertEqual($expected, $result); $result = Media::asset('subpath/file', 'my', array('base' => '/app/path/')); $expected = '/app/path//your/subpath/file.my'; $this->assertEqual($expected, $result); }