lithium\net\http\Media::path PHP Метод

path() публичный статический Метод

Returns the physical path to an asset in the /webroot directory of an application or plugin.
public static path ( $path, string $type, array $options = [] ) : string
$type string A valid asset type, i.e. `'js'`, `'cs'`, `'image'`, or another type registered with `Media::assets()`, or `'generic'`.
$options array The options used to calculate the path to the file.
Результат string Returns the physical filesystem path to an asset in the `/webroot` directory.
    public static function path($path, $type, array $options = array())
    {
        $defaults = array('base' => null, 'paths' => array(), 'suffix' => null, 'library' => true, 'scope' => false);
        if (!($base = static::_assets($type))) {
            $base = static::_assets('generic');
        }
        $options += $base + $defaults;
        $paths = $options['paths'];
        if ($options['scope']) {
            $root = static::webroot(false, $options['scope']);
        } else {
            $root = static::webroot($options['library']);
            Libraries::get(true, 'name') === $options['library'] ? end($paths) : reset($paths);
        }
        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);
    }

Usage Example

Пример #1
0
 public function testQueryUndefinedAssetTypes()
 {
     $base = Media::path('index.php', 'generic');
     $result = Media::path('index.php', 'foo');
     $this->assertEqual($result, $base);
     $base = Media::asset('/bar', 'generic');
     $result = Media::asset('/bar', 'foo');
     $this->assertEqual($result, $base);
 }