lithium\net\http\Media::filterAssetPath PHP Méthode

filterAssetPath() public static méthode

Performs checks and applies transformations to asset paths, including verifying that the virtual path exists on the filesystem, appending a timestamp, prepending an asset host, or applying a user-defined filter.
See also: lithium\net\http\Media::asset()
public static filterAssetPath ( string $asset, mixed $path, array $config, array $options = [] ) : mixed
$asset string A full asset path, relative to the public web path of the application.
$path mixed Path information for the asset type.
$config array The configuration array of the library from which the asset is being loaded.
$options array The array of options passed to `asset()` (see the `$options` parameter of `Media::asset()`).
Résultat mixed Returns a modified path to a web asset, or `false`, if the path fails a check.
    public static function filterAssetPath($asset, $path, array $config, array $options = array())
    {
        $config += array('assets' => null);
        if ($options['check'] || $options['timestamp']) {
            $file = static::path($asset, $options['type'], $options);
        }
        if ($options['check'] && !is_file($file)) {
            return false;
        }
        $isAbsolute = $asset && $asset[0] === '/';
        if ($isAbsolute && $options['base'] && strpos($asset, $options['base']) !== 0) {
            $asset = "{$options['base']}{$asset}";
        } elseif (!$isAbsolute) {
            $asset = String::insert(key($path), array('path' => $asset) + $options);
        }
        if (is_array($options['filter']) && !empty($options['filter'])) {
            $filter = $options['filter'];
            $asset = str_replace(array_keys($filter), array_values($filter), $asset);
        }
        if ($options['timestamp'] && is_file($file)) {
            $separator = strpos($asset, '?') !== false ? '&' : '?';
            $asset .= $separator . filemtime($file);
        }
        if ($host = $config['assets']) {
            $type = $options['type'];
            $env = Environment::get();
            $base = isset($host[$env][$type]) ? $host[$env][$type] : null;
            $base = isset($host[$type]) && !$base ? $host[$type] : $base;
            if ($base) {
                return "{$base}{$asset}";
            }
        }
        return $asset;
    }