lithium\net\http\Media::_assetOptions PHP Method

_assetOptions() protected static method

Initialize options for Media::asset().
protected static _assetOptions ( string $path, string $type, array $options ) : array
$path string The path to the asset.
$type string The asset type.
$options array Contains setting for finding and handling the path.
return array The initialized options.
    protected static function _assetOptions($path, $type, $options)
    {
        $defaults = array('base' => null, 'timestamp' => false, 'filter' => null, 'paths' => array(), 'suffix' => null, 'check' => false, 'library' => true);
        $base = isset($options['base']) ? rtrim($options['base'], '/') : '';
        $options += array('scope' => static::scope());
        $name = $options['scope'];
        if ($config = static::attached($name)) {
            $base = isset($config['base']) ? '/' . $config['base'] : $base;
            $defaults = array_merge($defaults, $config);
            if (preg_match('/^((?:[a-z0-9-]+:)?\\/\\/)([^\\/]*)/i', $base, $match)) {
                $options = array_merge($defaults, array('base' => rtrim($base . '/' . $defaults['prefix'], '/')));
            } else {
                $host = '';
                if ($defaults['absolute']) {
                    $host = $defaults['host'];
                    if (is_array($host)) {
                        $hash = substr(hexdec(md5($path)), 0, 10);
                        $index = (int) $hash % count($host);
                        if (is_array($defaults['scheme'])) {
                            $host = $defaults['scheme'][$index] . $host[$index];
                        } else {
                            $host = $defaults['scheme'] . $host[$index];
                        }
                    } else {
                        $host = $defaults['scheme'] . $defaults['host'];
                    }
                    $base = trim($base, '/');
                    $base = $base ? '/' . $base : '';
                }
                $options['base'] = rtrim($host . $base . '/' . $defaults['prefix'], '/');
            }
        }
        if (!($paths = static::_assets($type))) {
            $paths = static::_assets('generic');
        }
        return $options + $paths + $defaults;
    }