Extends
lithium\core\StaticObject
Returns the physical path to an asset in the `/webroot` directory of an application or
plugin.
Parameters
- string $path The path to a web asset, relative to the root path for its type. For example, for a JavaScript file in `/webroot/js/subpath/file.js`, the correct value for `$path` would be `'subpath/file.js'`.
- string $type A valid asset type, i.e. `'js'`, `'cs'`, `'image'`, or another type registered with `Media::assets()`, or `'generic'`.
- array $options The options used to calculate the path to the file.
Returns
string Returns the physical filesystem path to an asset in the `/webroot` directory.Source
public static function path($path, $type, array $options = array()) {
$defaults = array(
'base' => null,
'path' => array(),
'suffix' => null,
'library' => true
);
if (!$base = static::_assets($type)) {
$type = 'generic';
$base = static::_assets('generic');
}
$options += ($base + $defaults);
$config = Libraries::get($options['library']);
$root = static::webroot($options['library']);
$paths = $options['path'];
$config['default'] ? end($paths) : reset($paths);
$options['library'] = basename($config['path']);
if ($qOffset = strpos($path, '?')) {
$path = substr($path, 0, $qOffset);
}
if ($path[0] === '/') {
$file = $root . $path;
} else {
$template = str_replace('{:library}/', '', key($paths));
$insert = array('base' => $root) + compact('path');
$file = String::insert($template, $insert);
}
return realpath($file);
}